文件系统

Base.Filesystem.pwdFunction
pwd() -> AbstractString

Get the current working directory.

Examples

julia> pwd()
"/home/JuliaUser"

julia> cd("/home/JuliaUser/Projects/julia")

julia> pwd()
"/home/JuliaUser/Projects/julia"
source
Base.Filesystem.cdMethod
cd(dir::AbstractString=homedir())

Set the current working directory.

Examples

julia> cd("/home/JuliaUser/Projects/julia")

julia> pwd()
"/home/JuliaUser/Projects/julia"

julia> cd()

julia> pwd()
"/home/JuliaUser"
source
Base.Filesystem.cdMethod
cd(f::Function, dir::AbstractString=homedir())

Temporarily change the current working directory to dir, apply function f and finally return to the original directory.

Examples

julia> pwd()
"/home/JuliaUser"

julia> cd(readdir, "/home/JuliaUser/Projects/julia")
34-element Array{String,1}:
 ".circleci"
 ".freebsdci.sh"
 ".git"
 ".gitattributes"
 ".github"
 ⋮
 "test"
 "ui"
 "usr"
 "usr-staging"

julia> pwd()
"/home/JuliaUser"
source
Base.Filesystem.readdirFunction
readdir(dir::AbstractString=".") -> Vector{String}

Return the files and directories in the directory dir (or the current working directory if not given).

Examples

julia> readdir("/home/JuliaUser/Projects/julia")
34-element Array{String,1}:
 ".circleci"
 ".freebsdci.sh"
 ".git"
 ".gitattributes"
 ".github"
 ⋮
 "test"
 "ui"
 "usr"
 "usr-staging"
source
Base.Filesystem.walkdirFunction
walkdir(dir; topdown=true, follow_symlinks=false, onerror=throw)

Return an iterator that walks the directory tree of a directory. The iterator returns a tuple containing (rootpath, dirs, files). The directory tree can be traversed top-down or bottom-up. If walkdir encounters a SystemError it will rethrow the error by default. A custom error handling function can be provided through onerror keyword argument. onerror is called with a SystemError as argument.

Examples

for (root, dirs, files) in walkdir(".")
    println("Directories in $root")
    for dir in dirs
        println(joinpath(root, dir)) # path to directories
    end
    println("Files in $root")
    for file in files
        println(joinpath(root, file)) # path to files
    end
end
julia> mkpath("my/test/dir");

julia> itr = walkdir("my");

julia> (root, dirs, files) = first(itr)
("my", ["test"], String[])

julia> (root, dirs, files) = first(itr)
("my/test", ["dir"], String[])

julia> (root, dirs, files) = first(itr)
("my/test/dir", String[], String[])
source
Base.Filesystem.mkdirFunction
mkdir(path::AbstractString; mode::Unsigned = 0o777)

Make a new directory with name path and permissions mode. mode defaults to 0o777, modified by the current file creation mask. This function never creates more than one directory. If the directory already exists, or some intermediate directories do not exist, this function throws an error. See mkpath for a function which creates all required intermediate directories. Return path.

Examples

julia> mkdir("testingdir")
"testingdir"

julia> cd("testingdir")

julia> pwd()
"/home/JuliaUser/testingdir"
source
Base.Filesystem.mkpathFunction
mkpath(path::AbstractString; mode::Unsigned = 0o777)

Create all directories in the given path, with permissions mode. mode defaults to 0o777, modified by the current file creation mask. Return path.

Examples

julia> mkdir("testingdir")
"testingdir"

julia> cd("testingdir")

julia> pwd()
"/home/JuliaUser/testingdir"

julia> mkpath("my/test/dir")
"my/test/dir"

julia> readdir()
1-element Array{String,1}:
 "my"

julia> cd("my")

julia> readdir()
1-element Array{String,1}:
 "test"

julia> readdir("test")
1-element Array{String,1}:
 "dir"
source
Base.Filesystem.symlinkFunction
symlink(target::AbstractString, link::AbstractString)

Creates a symbolic link to target with the name link.

Note

This function raises an error under operating systems that do not support soft symbolic links, such as Windows XP.

source
Base.Filesystem.chmodFunction
chmod(path::AbstractString, mode::Integer; recursive::Bool=false)

Change the permissions mode of path to mode. Only integer modes (e.g. 0o777) are currently supported. If recursive=true and the path is a directory all permissions in that directory will be recursively changed. Return path.

source
Base.Filesystem.chownFunction
chown(path::AbstractString, owner::Integer, group::Integer=-1)

Change the owner and/or group of path to owner and/or group. If the value entered for owner or group is -1 the corresponding ID will not change. Only integer owners and groups are currently supported. Return path.

source
Base.Libc.RawFDType
RawFD

Primitive type which wraps the native OS file descriptor. RawFDs can be passed to methods like stat to discover information about the underlying file, and can also be used to open streams, with the RawFD describing the OS file backing the stream.

source
Base.statFunction
stat(file)

Returns a structure whose fields contain information about the file. The fields of the structure are:

NameDescription
sizeThe size (in bytes) of the file
deviceID of the device that contains the file
inodeThe inode number of the file
modeThe protection mode of the file
nlinkThe number of hard links to the file
uidThe user id of the owner of the file
gidThe group id of the file owner
rdevIf this file refers to a device, the ID of the device it refers to
blksizeThe file-system preferred block size for the file
blocksThe number of such blocks allocated
mtimeUnix timestamp of when the file was last modified
ctimeUnix timestamp of when the file was created
source
Base.Filesystem.lstatFunction
lstat(file)

Like stat, but for symbolic links gets the info for the link itself rather than the file it refers to. This function must be called on a file path rather than a file object or a file descriptor.

source
Base.Filesystem.upermFunction
uperm(file)

Get the permissions of the owner of the file as a bitfield of

ValueDescription
01Execute Permission
02Write Permission
04Read Permission

For allowed arguments, see stat.

source
Base.Filesystem.opermFunction
operm(file)

Like uperm but gets the permissions for people who neither own the file nor are a member of the group owning the file

source
Base.Filesystem.cpFunction
cp(src::AbstractString, dst::AbstractString; force::Bool=false, follow_symlinks::Bool=false)

Copy the file, link, or directory from src to dst. force=true will first remove an existing dst.

If follow_symlinks=false, and src is a symbolic link, dst will be created as a symbolic link. If follow_symlinks=true and src is a symbolic link, dst will be a copy of the file or directory src refers to. Return dst.

source
Base.downloadFunction
download(url::AbstractString, [localfile::AbstractString])

Download a file from the given url, optionally renaming it to the given local file name. If no filename is given this will download into a randomly-named file in your temp directory. Note that this function relies on the availability of external tools such as curl, wget or fetch to download the file and is provided for convenience. For production use or situations in which more options are needed, please use a package that provides the desired functionality instead.

Returns the filename of the downloaded file.

source
Base.Filesystem.mvFunction
mv(src::AbstractString, dst::AbstractString; force::Bool=false)

Move the file, link, or directory from src to dst. force=true will first remove an existing dst. Return dst.

Examples

julia> write("hello.txt", "world");

julia> mv("hello.txt", "goodbye.txt")
"goodbye.txt"

julia> "hello.txt" in readdir()
false

julia> readline("goodbye.txt")
"world"

julia> write("hello.txt", "world2");

julia> mv("hello.txt", "goodbye.txt")
ERROR: ArgumentError: 'goodbye.txt' exists. `force=true` is required to remove 'goodbye.txt' before moving.
Stacktrace:
 [1] #checkfor_mv_cp_cptree#10(::Bool, ::Function, ::String, ::String, ::String) at ./file.jl:293
[...]

julia> mv("hello.txt", "goodbye.txt", force=true)
"goodbye.txt"

julia> rm("goodbye.txt");
source
Base.Filesystem.rmFunction
rm(path::AbstractString; force::Bool=false, recursive::Bool=false)

Delete the file, link, or empty directory at the given path. If force=true is passed, a non-existing path is not treated as error. If recursive=true is passed and the path is a directory, then all contents are removed recursively.

Examples

julia> mkpath("my/test/dir");

julia> rm("my", recursive=true)

julia> rm("this_file_does_not_exist", force=true)

julia> rm("this_file_does_not_exist")
ERROR: IOError: unlink: no such file or directory (ENOENT)
Stacktrace:
[...]
source
Base.Filesystem.touchFunction
touch(path::AbstractString)

Update the last-modified timestamp on a file to the current time. Return path.

Examples

julia> write("my_little_file", 2);

julia> mtime("my_little_file")
1.5273815391135583e9

julia> touch("my_little_file");

julia> mtime("my_little_file")
1.527381559163435e9

We can see the mtime has been modified by touch.

source
Base.Filesystem.tempnameFunction
tempname()

Generate a temporary file path. This function only returns a path; no file is created. The path is likely to be unique, but this cannot be guaranteed.

Warning

This can lead to security holes if another process obtains the same file name and creates the file before you are able to. Open the file with JL_O_EXCL if this is a concern. Using mktemp() is also recommended instead.

source
Base.Filesystem.tempdirFunction
tempdir()

Gets the path of the temporary directory. On Windows, tempdir() uses the first environment variable found in the ordered list TMP, TEMP, USERPROFILE. On all other operating systems, tempdir() uses the first environment variable found in the ordered list TMPDIR, TMP, TEMP, and TEMPDIR. If none of these are found, the path "/tmp" is used.

source
Base.Filesystem.mktempMethod
mktemp(parent=tempdir(); cleanup=true) -> (path, io)

Return (path, io), where path is the path of a new temporary file in parent and io is an open file object for this path. The cleanup option controls whether the temporary file is automatically deleted when the process exits.

source
Missing docstring.

Missing docstring for Base.Filesystem.mktemp(::Function, ::Any). Check Documenter's build log for details.

Missing docstring.

Missing docstring for Base.Filesystem.mktempdir(::Any). Check Documenter's build log for details.

Missing docstring.

Missing docstring for Base.Filesystem.mktempdir(::Function, ::Any). Check Documenter's build log for details.

Base.Filesystem.isdirFunction
isdir(path) -> Bool

Return true if path is a directory, false otherwise.

Examples

julia> isdir(homedir())
true

julia> isdir("not/a/directory")
false

See also: isfile and ispath.

source
Base.Filesystem.isfileFunction
isfile(path) -> Bool

Return true if path is a regular file, false otherwise.

Examples

julia> isfile(homedir())
false

julia> f = open("test_file.txt", "w");

julia> isfile(f)
true

julia> close(f); rm("test_file.txt")

See also: isdir and ispath.

source
Base.Filesystem.homedirFunction
homedir() -> AbstractString

Return the current user's home directory.

Note

homedir determines the home directory via libuv's uv_os_homedir. For details (for example on how to specify the home directory via environment variables), see the uv_os_homedir documentation.

source
Base.Filesystem.dirnameFunction
dirname(path::AbstractString) -> AbstractString

Get the directory part of a path. Trailing characters ('/' or '\') in the path are counted as part of the path.

Examples

julia> dirname("/home/myuser")
"/home"

julia> dirname("/home/myuser/")
"/home/myuser"

See also: basename

source
Base.Filesystem.basenameFunction
basename(path::AbstractString) -> AbstractString

Get the file name part of a path.

Examples

julia> basename("/home/myuser/example.jl")
"example.jl"

See also: dirname

source
Base.@__FILE__Macro
@__FILE__ -> AbstractString

Expand to a string with the path to the file containing the macrocall, or an empty string if evaluated by julia -e <expr>. Return nothing if the macro was missing parser source information. Alternatively see PROGRAM_FILE.

source
Base.@__DIR__Macro
@__DIR__ -> AbstractString

Expand to a string with the absolute path to the directory of the file containing the macrocall. Return the current working directory if run from a REPL or if evaluated by julia -e <expr>.

source
Base.@__LINE__Macro
@__LINE__ -> Int

Expand to the line number of the location of the macrocall. Return 0 if the line number could not be determined.

source
Base.Filesystem.isabspathFunction
isabspath(path::AbstractString) -> Bool

Determine whether a path is absolute (begins at the root directory).

Examples

julia> isabspath("/home")
true

julia> isabspath("home")
false
source
Base.Filesystem.isdirpathFunction
isdirpath(path::AbstractString) -> Bool

Determine whether a path refers to a directory (for example, ends with a path separator).

Examples

julia> isdirpath("/home")
false

julia> isdirpath("/home/")
true
source
Base.Filesystem.joinpathFunction
joinpath(parts...) -> AbstractString

Join path components into a full path. If some argument is an absolute path or (on Windows) has a drive specification that doesn't match the drive computed for the join of the preceding paths, then prior components are dropped.

Examples

julia> joinpath("/home/myuser", "example.jl")
"/home/myuser/example.jl"
source
Base.Filesystem.abspathFunction
abspath(path::AbstractString) -> AbstractString

Convert a path to an absolute path by adding the current directory if necessary. Also normalizes the path as in normpath.

source
abspath(path::AbstractString, paths::AbstractString...) -> AbstractString

Convert a set of paths to an absolute path by joining them together and adding the current directory if necessary. Equivalent to abspath(joinpath(path, paths...)).

source
Base.Filesystem.normpathFunction
normpath(path::AbstractString) -> AbstractString

Normalize a path, removing "." and ".." entries.

Examples

julia> normpath("/home/myuser/../example.jl")
"/home/example.jl"
source
Base.Filesystem.realpathFunction
realpath(path::AbstractString) -> AbstractString

Canonicalize a path by expanding symbolic links and removing "." and ".." entries. On case-insensitive case-preserving filesystems (typically Mac and Windows), the filesystem's stored case for the path is returned.

(This function throws an exception if path does not exist in the filesystem.)

source
Base.Filesystem.relpathFunction
relpath(path::AbstractString, startpath::AbstractString = ".") -> AbstractString

Return a relative filepath to path either from the current directory or from an optional start directory. This is a path computation: the filesystem is not accessed to confirm the existence or nature of path or startpath.

source
Base.Filesystem.expanduserFunction
expanduser(path::AbstractString) -> AbstractString

On Unix systems, replace a tilde character at the start of a path with the current user's home directory.

source
Base.Filesystem.splitdirFunction
splitdir(path::AbstractString) -> (AbstractString, AbstractString)

Split a path into a tuple of the directory name and file name.

Examples

julia> splitdir("/home/myuser")
("/home", "myuser")
source
Base.Filesystem.splitdriveFunction
splitdrive(path::AbstractString) -> (AbstractString, AbstractString)

On Windows, split a path into the drive letter part and the path part. On Unix systems, the first component is always the empty string.

source
Base.Filesystem.splitextFunction
splitext(path::AbstractString) -> (AbstractString, AbstractString)

If the last component of a path contains a dot, split the path into everything before the dot and everything including and after the dot. Otherwise, return a tuple of the argument unmodified and the empty string.

Examples

julia> splitext("/home/myuser/example.jl")
("/home/myuser/example", ".jl")

julia> splitext("/home/myuser/example")
("/home/myuser/example", "")
source