Code Monkey home page Code Monkey logo

filepathsbase.jl's Introduction

FilePathsBase.jl

Build Status codecov.io

FilePathsBase.jl provides a type based approach to working with filesystem paths in julia.

Intallation

FilePathsBase.jl is registered, so you can to use Pkg.add to install it.

julia> Pkg.add("FilePathsBase")

Getting Started

Here are some common operations that you may want to perform with file paths.

#=
NOTE: We're loading our `/` operator for path concatenation into the currect scope, but non-path division operations will still fallback to the base behaviour.
=#
julia> using FilePathsBase; using FilePathsBase: /

julia> cwd()
p"/Users/rory/repos/FilePathsBase.jl"

julia> walkpath(cwd() / "docs") |> collect
23-element Array{Any,1}:
 p"/Users/rory/repos/FilePathsBase.jl/docs/.DS_Store"
 p"/Users/rory/repos/FilePathsBase.jl/docs/Manifest.toml"
 p"/Users/rory/repos/FilePathsBase.jl/docs/Project.toml"
 p"/Users/rory/repos/FilePathsBase.jl/docs/build"
 p"/Users/rory/repos/FilePathsBase.jl/docs/build/api.html"
 p"/Users/rory/repos/FilePathsBase.jl/docs/build/assets"
 p"/Users/rory/repos/FilePathsBase.jl/docs/build/assets/arrow.svg"
 p"/Users/rory/repos/FilePathsBase.jl/docs/build/assets/documenter.css"
 ...

julia> stat(p"docs/src/index.md")
Status(
  device = 16777223,
  inode = 32240108,
  mode = -rw-r--r--,
  nlink = 1,
  uid = 501 (rory),
  gid = 20 (staff),
  rdev = 0,
  size = 2028 (2.0K),
  blksize = 4096 (4.0K),
  blocks = 8,
  mtime = 2020-04-20T17:20:38.612,
  ctime = 2020-04-20T17:20:38.612,
)

julia> relative(p"docs/src/index.md", p"src/")
p"../docs/src/index.md"

julia> normalize(p"src/../docs/src/index.md")
p"docs/src/index.md"

julia> absolute(p"docs/src/index.md")
p"/Users/rory/repos/FilePathsBase.jl/docs/src/index.md"

julia> islink(p"docs/src/index.md")
true

julia> canonicalize(p"docs/src/index.md")
p"/Users/rory/repos/FilePathsBase.jl/README.md"

julia> parents(p"./docs/src")
2-element Array{PosixPath,1}:
 p"."
 p"./docs"

julia> parents(absolute(p"./docs/src"))
6-element Array{PosixPath,1}:
 p"/"
 p"/Users"
 p"/Users/rory"
 p"/Users/rory/repos"
 p"/Users/rory/repos/FilePathsBase.jl"
 p"/Users/rory/repos/FilePathsBase.jl/docs"

julia> absolute(p"./docs/src")[1:end-1]
("Users", "rory", "repos", "FilePathsBase.jl", "docs")

julia> tmpfp = mktempdir(SystemPath)
p"/var/folders/vz/zx_0gsp9291dhv049t_nx37r0000gn/T/jl_1GCBFT"

julia> sync(p"/Users/rory/repos/FilePathsBase.jl/docs", tmpfp / "docs")
p"/var/folders/vz/zx_0gsp9291dhv049t_nx37r0000gn/T/jl_1GCBFT/docs"

julia> exists(tmpfp / "docs" / "make.jl")
true

julia> m = mode(tmpfp / "docs" / "make.jl")
Mode("-rw-r--r--")

julia> m - readable(:ALL)
Mode("--w-------")

julia> m + executable(:ALL)
Mode("-rwxr-xr-x")

julia> chmod(tmpfp / "docs" / "make.jl", "+x")
"/var/folders/vz/zx_0gsp9291dhv049t_nx37r0000gn/T/jl_1GCBFT/docs/make.jl"

julia> mode(tmpfp / "docs" / "make.jl")
Mode("-rwxr-xr-x")

# Count LOC
julia> mapreduce(+, walkpath(cwd() / "src")) do x
           extension(x) == "jl" ? count("\n", read(x, String)) : 0
       end
3020

# Concatenate multiple files.
julia> str = mapreduce(*, walkpath(tmpfp / "docs" / "src")) do x
           read(x, String)
       end
"# API\n\nAll the standard methods for working with paths in base julia exist in the FilePathsBase.jl. The following describes the rough mapping of method names. Use `?` at the REPL to get the documentation and arguments as they may be different than the base implementations.\n\n..."

# Could also write the result to a file with `write(newfile, str)`)

julia> rm(tmpfp; recursive=true)

julia> exists(tmpfp)
false

filepathsbase.jl's People

Contributors

rofinn avatar davidanthoff avatar oxinabox avatar bsnelling avatar alhirzel avatar omus avatar vtjnash avatar ararslan avatar iamed2 avatar expandingman avatar juliatagbot avatar metab0t avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.