Filepaths in julia with FilePathsBase
FilePathsBase
Quick start
Ref List
Operations
A table of common operations with Filesystem and FilePathsBase.
Filesystem | FilePathsBase.jl |
---|---|
"/home/user/docs" | p"/home/user/docs" |
– | Path() |
pwd() | pwd(SystemPath) or cwd() |
homedir() | homedir(SystemPath) or home() |
cd() | cd() |
joinpath() | / |
basename() | basename() |
– | hasparent, parents, parent |
splitext | splitext |
– | filename |
– | extension |
– | extensions |
ispath | exists |
realpath | canonicalize |
normpath | normalize |
abspath | absolute |
relpath | relative |
stat | stat |
lstat | lstat |
filemode | mode |
filesize | filesize |
mtime | modified |
ctime | created |
isdir | isdir |
isfile | isfile |
islink | islink |
issocket | issocket |
isfifo | isfifo |
ischardev | ischardev |
isblockdev | isblockdev |
isexecutable (deprecated) | isexecutable |
iswritable (deprecated) | iswritable |
isreadable (deprecated) | isreadable |
ismount | ismount |
isabspath | isabsolute |
splitdrive()[1] | drive |
– | root (property) |
split(p, "/") | segments (property) |
expanduser | expanduser |
mkdir | mkdir |
mkpath | N/A (use mkdir) |
symlink | symlink |
cp | cp |
mv | mv |
download | download |
readdir | readdir |
– | readpath |
walkpath | walkpath |
rm | rm |
touch | touch |
tempname() | tempname(::Type{<:AbstractPath}) (or tmpname) |
tempdir() | tempdir(::Type{<:AbstractPath}) (or tmpdir) |
mktemp() | mktemp(::Type{<:AbstractPath}) (or mktmp) |
mktempdir() | mktempdir(::Type{<:AbstractPath}) (or mktmpdir) |
chmod | chmod (recursive unix-only) |
chown (unix only) | chown (unix only) |
read | read |
write | write |
@__DIR__ | @__PATH__ |
@__FILE__ | @__FILEPATH__ |
Aliases
A slightly reduced list of operations/aliases that will work with both strings and path types. The Filesystem
and FilePathsBase
columns indicate what type will be returned from each each library. As you'd expect, most return types match the input argument(s).
Function Name | Filesystem | FilePathsBase |
---|---|---|
cd | AbstractString | AbstractPath |
joinpath | AbstractString | AbstractPath |
basename | AbstractString | AbstractString |
splitext | (AbstractString, AbstractString) | (AbstractPath, AbstractString) |
ispath | Bool | Bool |
realpath | AbstractString | AbstractPath |
normpath | AbstractString | AbstractPath |
abspath | AbstractString | AbstractPath |
relpath | AbstractString | AbstractPath |
stat | StatStruct | FilePathsBase.Status |
lstat | StatStruct | FilePathsBase.Status |
filemode | UInt64 | FilePathsBase.Mode |
filesize | Int64 | Int64 |
mtime | Float64 | Float64 |
ctime | Float64 | Float64 |
isdir | Bool | Bool |
isfile | Bool | Bool |
islink | Bool | Bool |
issocket | Bool | Bool |
isfifo | Bool | Bool |
ischardev | Bool | Bool |
isblockdev | Bool | Bool |
ismount | Bool | Bool |
isabspath | Bool | Bool |
expanduser | AbstractString | AbstractPath |
mkdir | AbstractString | AbstractPath |
mkpath | AbstractString | AbstractPath |
symlink | Nothing | Nothing |
cp | AbstractString | AbstractPath |
mv | AbstractString | AbstractPath |
download | AbstractString | AbstractPath |
readdir | AbstractString | AbstractString |
rm | Nothing | Nothing |
touch | AbstractString | AbstractPath |
chmod | AbstractString | AbstractPath |
chown | AbstractString | AbstractPath |
read(fp, T) | T | T |
write | Int64 | Int64 |
FilePaths
FilePaths extends FilePathsBase with several useful functions:
More about Mode in FilePathsBase
Mode
type provides abstraction for working with posix file permissions
struct Mode
m::UInt64
end
# user groups symbols:
:ALL
:USER
:GROUP
:OTHER
# dispatch base functions for dealing with Mode:
+, -, Base.oct,
isdir, isfile, islink, issocket, isfifo, ischardev, isblockdev
iswritable, isreadable, isexecutable # isexecutable is newly definde in FilePathsBase
# function alias
executable(usr_grps::Symbol...) = Mode(EXEC, usr_grps...)
readable(usr_grps::Symbol...) = Mode(READ, usr_grps...)
writable(usr_grps::Symbol...) = Mode(WRITE, usr_grps...)
julia