Engee documentation

The file system

read(filename::AbstractString)

Reads the entire contents of the file as Vector{UInt8}.

read(filename::AbstractString, String)

Reads the entire contents of the file as a string.

read(filename::AbstractString, args...)

Opens the file and reads its contents. 'args` is passed to read: this is equivalent to open(io->read(io, args...), filename).

write(filename::AbstractString, content)

Writes the canonical binary representation of `content' to a file that will be created if it does not already exist, or overwritten otherwise.

Returns the number of bytes written to the file.

pwd() -> String

Returns the current working directory.

See also the description cd, tempdir.

Examples

julia> pwd()
"/home/JuliaUser"

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

julia> pwd()
"/home/JuliaUser/Projects/julia"
cd(dir::AbstractString=homedir())

Sets the current working directory.

See also the description pwd, mkdir, mkpath, mktempdir.

Examples

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

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

julia> cd()

julia> pwd()
"/home/JuliaUser"
cd(f::Function, dir::AbstractString=homedir())

Temporarily changes the current working directory to dir, applies the f function, and returns to the source 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"
readdir(dir::AbstractString=pwd();
    join::Bool = false,
    sort::Bool = true,
) -> Vector{String}

Returns names in the dir directory or the current working directory if it is not specified. If join is set to false, readdir returns only the names in the directory in their original form; if join is set to true, it returns joinpath(dir, name) for each name', so the returned strings are full paths. To get the absolute paths again, call `readdir with the absolute directory path and `join' set to true.

By default, readdir' sorts the list of returned names. To skip sorting names and get them in the order they are listed in the file system, you can use `readdir(dir, sort=false).

See also the description walkdir.

Compatibility: Julia 1.4

Named arguments join and sort require a Julia version of at least 1.4.

Examples

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

julia> readdir()
30-element Array{String,1}:
 ".appveyor.yml"
 ".git"
 ".gitattributes"
 ⋮
 "ui"
 "usr"
 "usr-staging"

julia> readdir(join=true)
30-element Array{String,1}:
 "/home/JuliaUser/dev/julia/.appveyor.yml"
 "/home/JuliaUser/dev/julia/.git"
 "/home/JuliaUser/dev/julia/.gitattributes"
 ⋮
 "/home/JuliaUser/dev/julia/ui"
 "/home/JuliaUser/dev/julia/usr"
 "/home/JuliaUser/dev/julia/usr-staging"

julia> readdir("base")
145-element Array{String,1}:
 ".gitignore"
 "Base.jl"
 "Enums.jl"
 ⋮
 "version_git.sh"
 "views.jl"
 "weakkeydict.jl"

julia> readdir("base", join=true)
145-element Array{String,1}:
 "base/.gitignore"
 "base/Base.jl"
 "base/Enums.jl"
 ⋮
 "base/version_git.sh"
 "base/views.jl"
 "base/weakkeydict.jl"

julia> readdir(abspath("base"), join=true)
145-element Array{String,1}:
 "/home/JuliaUser/dev/julia/base/.gitignore"
 "/home/JuliaUser/dev/julia/base/Base.jl"
 "/home/JuliaUser/dev/julia/base/Enums.jl"
 ⋮
 "/home/JuliaUser/dev/julia/base/version_git.sh"
 "/home/JuliaUser/dev/julia/base/views.jl"
 "/home/JuliaUser/dev/julia/base/weakkeydict.jl"
walkdir(dir; topdown=true, follow_symlinks=false, onerror=throw)

Returns an iterator that traverses the directory tree. The iterator returns a tuple containing (rootpath, dirs, files). The directory tree can be traversed from top to bottom or from bottom to top. If walkdir or stat detects an IOError', the default error will be re-output. The user error handling function can be provided using the named 'onerror argument. 'onerror` is called with IOError as an argument.

See also the description readdir.

Examples

for (root, dirs, files) in walkdir(".")
    println("Directories in $root")
    for dir in dirs
        println(joinpath(root, dir)) # путь к каталогам
    end
    println("Files in $root")
    for file in files
        println(joinpath(root, file)) # путь к файлам
    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[])
mkdir(path::AbstractString; mode::Unsigned = 0o777)

Creates a directory named path with mode permissions. The default value of mode' is `0o777'. It is changed 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 returns an error. For information about the function that creates all the necessary intermediate directories, see the description `mkpath. Returns the `path'.

Examples

julia> mkdir("testingdir")
"testingdir"

julia> cd("testingdir")

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

Creates all necessary intermediate directories in the path. Directories are created with the mode permissions, which have the default value of 0o777 and are modifiable by the current file creation mask. As opposed to mkdir, mkpath' does not return an error if the `path' (or parts of it) already exists. However, an error is thrown if the `path (or parts of it) points to an existing file. Returns the `path'.

If path contains a file name, you probably want to use `mkpath(dirname(path))' to avoid creating a directory using the file name.

Examples

julia> cd(mktempdir())

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"

julia> mkpath("intermediate_dir/actually_a_directory.txt") # creates two directories
"intermediate_dir/actually_a_directory.txt "

julia> isdir("intermediate_dir/actually_a_directory.txt")
true
hardlink(src::AbstractString, dst::AbstractString)

Creates a hard link to an existing src source file named dst'. The destination `dst should not exist.

See also the description symlink.

Compatibility: Julia 1.8

This method was added in Julia 1.8.

symlink(target::AbstractString, link::AbstractString; dir_target = false)

Creates a symbolic link to a target named `link'.

In Windows, symbolic links must be explicitly declared as pointing to a directory or not. If the target already exists, the link type will be determined automatically by default. However, if target does not exist, this function will create a symbolic link to the file by default, unless dir_target is set to true'. Note that if the user sets `dir_target, but the target exists and is a file, a symbolic link to the directory will still be created, but its dereference will fail, just as if the user had created a symbolic link to the file (by calling symlink()`with `dir_target with the value false before creating the directory) and tried to dereference it for the directory.

In addition, there are two ways to create a link in Windows: symbolic links and connection points. Junction points are slightly more efficient, but do not support relative paths, so if a relative symbolic link to a directory is requested (as indicated by using isabspath(target), which returns false), a symbolic link will be used; otherwise, a junction point will be used. It is recommended to create symbolic links in Windows only after creating the files or directories they point to.

See also the description hardlink.

This feature causes an error on operating systems that do not support soft symbolic links, such as Windows XP.

Compatibility: Julia 1.6

The named argument `dir_target' was added in Julia 1.6. Before that, symbolic links to non-existent paths in Windows were always file symbolic links, and relative symbolic links to directories were not supported.

readlink(path::AbstractString) -> String

Returns the target location that the symbolic link path points to.

chmod(path::AbstractString, mode::Integer; recursive::Bool=false)

Changes the permission mode path to mode. Currently, only integer modes are supported (for example, 0o777). . If recursive=true and the path is a directory, all permissions in that directory will be changed recursively. Returns the `path'.

Before Julia 1.6, it was impossible to work correctly with file system ACLs in Windows, so read-only bits were set in files. It is now possible to manage ACL lists.

chown(path::AbstractString, owner::Integer, group::Integer=-1)

Changes the owner and/or group path to owner and/or group'. If the value `-1 is entered for owner or group, the corresponding identifier will not change. Currently, only integer owner and group are supported. Returns the `path'.

RawFD

A primitive type that wraps the OS’s own file descriptor. RawFD can be passed to methods such as stat, to detect information about the base file, and can also be used to open streams with RawFD describing the OS file supporting the stream.

stat(file)

Returns a structure whose fields contain information about the file. The structure fields are listed below.

Name Type Description

desc

Union{String, Base.OS_HANDLE}

OS file path or descriptor

size

Int64

File size (in bytes)

device

UInt

ID of the device containing the file

inode

UInt

The number of the file’s index descriptor

mode

UInt

File protection mode

nlink

Int

Number of hard links per file

uid

UInt

The ID of the user — the owner of the file

gid

UInt

ID of the file owner’s group

rdev

UInt

If this file links to a device, the ID of the device it links to is

blksize

Int64

Preferred file system block size for a file

blocks

Int64

The number of allocated 512-byte blocks

mtime

Float64

A Unix timestamp indicating the time when a file was last modified

ctime

Float64

A Unix timestamp indicating the time when file metadata was changed

diskstat(path=pwd())

Returns statistics in bytes about the disk containing the file or directory pointed to by path. If no arguments are passed, statistics about the disk containing the current working directory are returned.

Compatibility: Julia 1.8

This method was added in Julia 1.8.

lstat(file)

Similarly stat, but for symbolic links, gets information for the link itself, not for the file it points to. This function should be called for the file path, not the file object or file descriptor.

ctime(file)

Equivalent to `stat(file).ctime'.

mtime(file)

Equivalent to `stat(file).mtime'.

filemode(file)

Equivalent to `stat(file).mode'.

filesize(path...)

Equivalent to `stat(file).size'.

uperm(file)

Returns the permissions of the file owner as a bit field

Meaning Description

01

Permission to execute

02

Write permission

04

Read permission

For a list of acceptable arguments, see the description stat.

gperm(file)

Similarly uperm, but returns the permissions of the group that owns the file.

operm(file)

Similarly uperm, but returns permissions for users who are not the owners of the file and are not part of the group that owns the file.

cp(src::AbstractString, dst::AbstractString; force::Bool=false, follow_symlinks::Bool=false)

Copies a file, link, or directory from src to dst'. With `force=true, the existing dst will be deleted first.

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 pointed to by src. Returns `dst'.

The cp function is different from the cp command. The 'cp` function always operates based on the assumption that dst is a file, while the command performs different operations depending on whether dst is a directory or a file. When using force=true, when dst is a directory, all contents located in the dst directory will be lost, and dst will become a file with the contents of src.

download(url::AbstractString, [path::AbstractString = tempname()]) -> path

Downloads the file from the specified URL and saves it in the path location or, if not specified, in a temporary path. Returns the path of the downloaded file.

Starting with Julia 1.6, this feature is considered obsolete and is only a thin shell for Downloads.download. In the new code, you should use that function directly, rather than calling this one.

mv(src::AbstractString, dst::AbstractString; force::Bool=false)

Moves a file, link, or directory from src to dst'. With `force=true, the existing dst will be deleted first. Returns `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");
rm(path::AbstractString; force::Bool=false, recursive::Bool=false)

Deletes a file, link, or empty directory using the specified path. If force=true is passed, a non-existent path is not considered an error. If recursive=true is passed and the path is a directory, all contents are recursively deleted.

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("this_file_does_not_exist"): no such file or directory (ENOENT)
Stacktrace:
[...]
Base.touch(::Pidfile.LockMonitor)

Updates the `mtime' for the lock to indicate that it is still up to date.

See also the description of the refresh keyword in the [mkpidlock] constructor.


touch(path::AbstractString)
touch(fd::File)

Updates the timestamp of the last modification in the file according to the current time.

If the file does not exist, a new file is created.

Returns the `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 see that mtime changed by the touch function.

tempname(parent=tempdir(); cleanup=true) -> String

Creates a path to a temporary file. This function returns only the path, the file is not created. The path is likely to be unique, but this is not guaranteed due to the very low probability that two simultaneous calls to tempname will create the same file name. The name is guaranteed to differ from the names of all files that already exist at the time of calling tempname.

When called without arguments, the temporary name will be the absolute path to the temporary name in the system temporary directory specified by tempdir()'. If the `parent directory argument is set, the temporary path will be located in this directory.

The cleanup parameter controls whether the process tries to automatically delete the returned path at completion. Note that the tempname function does not create any file or directory in the returned location, so cleanup is performed only after the file or directory is created there. If you do this and the cleanup parameter is set to `true', the path will be deleted at the end of the process.

Compatibility: Julia 1.4

The arguments parent and cleanup were added in version 1.4. Prior to Julia 1.4, the path tempname was never deleted at the end of the process.

There may be security breaches if another process gets the same file name and creates the file before you do. If this situation is a concern, open the file using JL_O_EXCL'. In addition, it is also recommended to use `mktemp().

tempdir()

Returns the path to the temporary directory. In Windows` 'tempdir()` uses the first environment variable found in the ordered list TMP, TEMP, USERPROFILE'. In all other operating systems, tempdir() uses the first environment variable found in the ordered list of TMPDIR, TMP, TEMP, and TEMPDIR. If nothing is found, the path `"/tmp" is used.

mktemp(parent=tempdir(); cleanup=true) -> (path, io)

Returns (path, io), where path is the path to the new temporary file in parent, and io is the object of the open file for this path. The 'cleanup` parameter controls the automatic deletion of a temporary file at the end of the process.

Compatibility: Julia 1.3

The named cleanup argument was added in Julia 1.3. In addition, starting with version 1.3, temporary paths created with mktemp will be deleted in Julia upon completion of the Julia process, if the cleanup parameter the value false is not explicitly set.

mktemp(f::Function, parent=tempdir())

Applies the function f to the result mktemp(parent) and deletes the temporary file upon completion.

See also the description mktempdir.

mktempdir(parent=tempdir(); prefix="jl_", cleanup=true) -> path

Creates a temporary directory in the parent directory with a name based on the specified prefix prefix and a random suffix, and returns the path to it. Also, on some platforms, all end characters are They can be replaced with random characters in the prefix. If the parent does not exist, an error occurs. The 'cleanup` parameter controls the automatic deletion of the temporary directory at the end of the process.

Compatibility: Julia 1.2

The named prefix argument was added in Julia 1.2.

Compatibility: Julia 1.3

The named cleanup argument was added in Julia 1.3. In addition, starting with version 1.3, temporary paths created with mktempdir will be deleted in Julia upon completion of the Julia process, if the cleanup parameter the value false is not explicitly set.

See also the description mktemp, mkdir.

mktempdir(f::Function, parent=tempdir(); prefix="jl_")

Applies the function f to the result mktempdir(parent; prefix) and deletes the temporary directory and all its contents upon completion.

See also the description mktemp, mkdir.

Compatibility: Julia 1.2

The named prefix argument was added in Julia 1.2.

isblockdev(path) -> Bool

Returns true if the path' is a block device, otherwise it returns `false.

ischardev(path) -> Bool

Returns true if path' is a character device, otherwise it returns `false.

isdir(path) -> Bool

Returns true if path is a directory, otherwise it returns `false'.

Examples

julia> isdir(homedir())
true

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

See also the description isfile and ispath.

isfifo(path) -> Bool

Returns true if the path is FIFO, otherwise it returns false.

isfile(path) -> Bool

Returns true if the path' is a regular file, otherwise it returns `false.

Examples

julia> isfile(homedir())
false

julia> filename = "test_file.txt";

julia> write(filename, "Hello world!");

julia> isfile(filename)
true

julia> rm(filename);

julia> isfile(filename)
false

See also the description isdir and ispath.

islink(path) -> Bool

Returns true if path is a symbolic link, otherwise it returns false.

ismount(path) -> Bool

Returns true if path is the connection point, otherwise it returns `false'.

ispath(path) -> Bool

Returns true if a valid file system object exists along the path, otherwise it returns false. This is a generalization isfile, 'isdir`, etc.

issetgid(path) -> Bool

Returns true if the setgid flag is set for path, otherwise it returns false.

issetuid(path) -> Bool

Returns true if the setuid flag is set for path, otherwise it returns false.

issocket(path) -> Bool

Returns true if path is a socket, otherwise it returns `false'.

issticky(path) -> Bool

Returns true if the pinning bit is set for path, otherwise it returns false.

homedir() -> String

Returns the current user’s home directory.

'homedir` defines the home directory using uv_os_homedir from `libuv'. For more information (for example, about specifying the home directory using environment variables), see http://docs.libuv.org/en/v1.x/misc.html#c.uv_os_homedir [documentation for `uv_os_homedir'].

See also the description Sys.username.

dirname(path::AbstractString) -> String

Returns the part of the path containing the folder. The end characters ('/' or ") in the path are considered part of the path.

Examples

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

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

See also the description basename.

basename(path::AbstractString) -> String

Returns the part of the path containing the file name.

This function is slightly different from the Unix program basename, where trailing slashes are ignored, that is, $basename /foo/bar/ returns bar, whereas basename in Julia returns an empty string "".

Examples

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

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

See also the description dirname.

isabspath(path::AbstractString) -> Bool

Determines whether the path is absolute (starts from the root directory).

Examples

julia> isabspath("/home")
true

julia> isabspath("home")
false
isdirpath(path::AbstractString) -> Bool

Determines whether the path belongs to a directory (for example, it ends with a path separator).

Examples

julia> isdirpath("/home")
false

julia> isdirpath("/home/")
true
joinpath(parts::AbstractString...) -> String
joinpath(parts::Vector{AbstractString}) -> String
joinpath(parts::Tuple{AbstractString}) -> String

Combines path components into a complete path. If any argument is an absolute path or (in Windows) has a disk specification that does not match the disk defined for combining previous paths, the previous components are discarded.

Note that since there is a current directory for each disk in Windows, joinpath("c:", "foo") represents the path relative to the current directory on the c: disk, so it looks like c:foo, not c:\foo . Moreover, joinpath treats it as a non-absolute path and ignores the case of the drive letter, so joinpath("C:\A","c:b") = "C:\A\b".

Examples

julia> joinpath("/home/myuser", "example.jl")
"/home/myuser/example.jl"
julia> joinpath(["/home/myuser", "example.jl"])
"/home/myuser/example.jl"
abspath(path::AbstractString) -> String

Converts the path to an absolute path with the addition of the current directory, if necessary. It also normalizes the path as in normpath.

Examples

If you are in the JuliaExample directory, and the data you are using is two levels higher relative to the JuliaExample directory, you can write:

abspath("../../data")

The result will be a path like `"/home/JuliaUser/data/"'.

See also the description joinpath, pwd and expanduser.


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

Converts a set of paths to an absolute path, combining them and adding the current directory, if necessary. Equivalent to abspath(joinpath(path, paths...)).

normpath(path::AbstractString) -> String

Normalizes the path by removing the "." and ".." elements and changing the "/" to the canonical path separator for the system.

Examples

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

julia> normpath("Documents/Julia") == joinpath("Documents", "Julia")
true

normpath(path::AbstractString, paths::AbstractString...) -> String

Converts a set of paths into a normalized path with their union and the removal of the elements "." and "..". Equivalent to normpath(joinpath(path, paths...)).

realpath(path::AbstractString) -> String

Canonicalizes the path by extending symbolic links and removing the "." and ".." elements. In case-sensitive and case-insensitive file systems (usually Mac and Windows), the case stored in the file system is returned for the path.

(This function throws an exception if the `path' does not exist in the file system.)

relpath(path::AbstractString, startpath::AbstractString = ".") -> String

Returns the relative file path for path either from the current directory or from an optional start directory. The path is calculated: there are no calls to the file system to confirm the existence or nature of path or `startpath'.

In Windows, case is taken into account for all parts of the path, except for the drive letters. If path and startpath refer to different disks, the absolute path path is returned.

expanduser(path::AbstractString) -> AbstractString

On Unix systems, it replaces the tilde character at the beginning of the path with the current user’s home directory.

See also the description contractuser.

contractuser(path::AbstractString) -> AbstractString

If the path starts with homedir() on Unix systems, replace it with a tilde character.

See also the description expanduser.

samefile(path_a::AbstractString, path_b::AbstractString)

Checks whether the paths path_a and path_b refer to the same existing file or directory.

splitdir(path::AbstractString) -> (AbstractString, AbstractString)

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

Examples

julia> splitdir("/home/myuser")
("/home", "myuser")
splitdrive(path::AbstractString) -> (AbstractString, AbstractString)

In Windows, it divides the path into a part with a drive letter and a part with a path. On Unix systems, the first component is always an empty string.

splitext(path::AbstractString) -> (String, String)

If the last component of the path contains one or more points, it divides the path into everything that is before the last point, and everything starting from this point onwards. Otherwise, a tuple of an unchanged argument and an empty string is returned. splitext is short for split extension, split by extension.

Examples

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

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

julia> splitext("/home/my.user/example")
("/home/my.user/example", "")
splitpath(path::AbstractString) -> Vector{String}

Divides the file path into all components. This is the reverse function of `joinpath'. Returns an array of substrings, one for each directory or file in the path, including the root directory (if any).

Compatibility: Julia 1.1

This feature requires a Julia version of at least 1.1.

Examples

julia> splitpath("/home/myuser/example.jl")
4-element Vector{String}:
 "/"
 "home"
 "myuser"
 "example.jl"