FilePaths.jl

Build Statuscodecov

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

Intallation:

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

julia> Pkg.add("FilePaths")

Usage:

julia> using FilePaths

The first important difference about working with paths in FilePaths.jl is that a path is an immutable list (Tuple) of strings, rather than simple a string.

Path creation:

julia> Path("~/repos/FilePaths.jl/")
Paths.PosixPath(("~","repos","FilePaths.jl",""))

or

julia> p"~/repos/FilePaths.jl/"
Paths.PosixPath(("~","repos","FilePaths.jl",""))

Human readable file status info:

julia> stat(p"README.md")
Status(
  device = 16777220,
  inode = 48428965,
  mode = -rw-r--r--,
  nlink = 1,
  uid = 501,
  gid = 20,
  rdev = 0,
  size = 1880 (1.8K),
  blksize = 4096 (4.0K),
  blocks = 8,
  mtime = 2016-02-16T00:49:27,
  ctime = 2016-02-16T00:49:27,
)

Working with permissions:

julia> m = mode(p"README.md")
-rw-r--r--

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

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

julia> chmod(p"README.md", "+x")

julia> mode(p"README.md")
-rwxr-xr-x

julia> chmod(p"README.md", m)

julia> m = mode(p"README.md")
-rw-r--r--

julia> chmod(p"README.md", user=(READ+WRITE+EXEC), group=(READ+WRITE), other=READ)

julia> mode(p"README.md")
-rwxrw-r--

Reading and writing directly to file paths:

julia> write(p"testfile", "foobar")
6

julia> read(p"testfile")
"foobar"

All the standard methods for working with paths in base julia exist in the FilePaths.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.

BaseFilePaths.jl
pwd()cwd()
homedir()home()
cd()cd()
joinpath()joinpath()
basename()basename()
splitext(basename())[1]filename
splitext(basename())[2]extension
N/Aextensions
ispathexists
realpathreal
normpathnorm
abspathabs
relpathrelative
statstat
lstatlstat
filemodemode
mtimemodified
ctimecreated
isdirisdir
isfileisfile
islinkislink
issocketissocket
isfifoisfifo
ischardevischardev
isblockdevisblockdev
isexecutable (deprecated)isexecutable
iswritable (deprecated)iswritable
isreadable (deprecated)isreadable
ismountismount
isabspathisabs
splitdrive()[1]drive
N/Aroot
expanduserexpanduser
mkdirmkdir
mkpathN/A (use mkdir)
symlinksymlink
cpcopy
mvmove
rmremove
touchtouch
tempnametmpname
tempdirtmpdir
mktempmktmp
mktempdirmktmpdir
chmodchmod (recursive unix-only)
chown (unix only)chown (unix only)
N/Aread
N/Awrite

TODO:

  • cross platform chmod and chown