module FileUtils

Extended Modules

Defined in:

file_utils.cr

Instance Method Summary

Instance Method Detail

def cd(path : String) #

Changes the current working directory of the process to the given string path. Alias of Dir.cd.

FileUtils.cd("to/directory")

[View source]
def cd(path : String, &block) #

Changes the current working firectory of the process to the given string path and invoked the block, restoring the original working directory when the block exits. Alias of Dir.cd with block.

FileUtils.cd("to/directory") { puts "Do something useful here!" }

[View source]
def cmp(filename1 : String, filename2 : String) #

Compares two files filename1 to filename2 to determine if they are identical. Returns true if content are the same, false otherwise.

FileUtils.cmp("foo.cr", "bar.cr")

[View source]
def cmp(stream1 : IO, stream2 : IO) #

Compares two streams stream1 to stream2 to determine if they are identical. Returns true if content are the same, false otherwise.

FileUtils.cmp(stream1 : IO, stream2 : IO)

[View source]
def cp(src_path : String, dest : String) #

Copies the file src_path to the file or directory dest. If dest is a directory, a file with the same basename as src_path is created in dest Permission bits are copied too.

FileUtils.cp("file_utils.cr", "file_utils_copy.cr")

[View source]
def cp(srcs : Enumerable(String), dest : String) #

Copies a list of files src to dest. dest must be an existing directory.

FileUtils.cp({"cgi.cr", "complex.cr", "date.cr"}, "files")

[View source]
def cp_r(src_path : String, dest_path : String) #

Copies a file or directory src_path to dest_path If src_path is a directory, this method copies all its contents recursively

FileUtils.cp_r("src_dir", "src_dir_copy")

[View source]
def mkdir(path : String, mode = 511) : Nil #

Creates a new directory at the given path. The linux-style permission mode can be specified, with a default of 777 (0o777). Alias of Dir.mkdir

FileUtils.mkdir("foo")

[View source]
def mkdir(paths : Enumerable(String), mode = 511) : Nil #

Creates a new directory at the given paths. The linux-style permission mode can be specified, with a default of 777 (0o777).

FileUtils.mkdir(["foo", "bar"])

[View source]
def mkdir_p(path : String, mode = 511) : Nil #

Creates a new directory at the given path, including any non-existing intermediate directories. The linux-style permission mode can be specified, with a default of 777 (0o777). Alias of Dir.mkdir_p

FileUtils.mkdir_p("foo")

[View source]
def mkdir_p(paths : Enumerable(String), mode = 511) : Nil #

Creates a new directory at the given paths, including any non-existing intermediate directories. The linux-style permission mode can be specified, with a default of 777 (0o777).

FileUtils.mkdir_p(["foo", "bar"])

[View source]
def mv(srcs : Enumerable(String), dest : String) : Nil #

Moves every srcs to dest.

FileUtils.mv(["afile", "foo", "bar"], "src")

[View source]
def mv(src_path : String, dest_path : String) : Nil #

Moves src_path to dest_path. Alias of File.rename

FileUtils.mv("afile", "afile.cr")

[View source]
def pwd : String #

Returns the current working directory. Alias of Dir.current

FileUtils.pwd

[View source]
def rm(path : String) : Nil #

Deletes the path file given. Alias of File.delete

FileUtils.rm("afile.cr")

[View source]
def rm(paths : Enumerable(String)) : Nil #

Deletes all paths file given.

FileUtils.rm(["afile.cr", "bfile.cr"])

[View source]
def rm_r(path : String) : Nil #

Deletes a file or directory path If path is a directory, this method removes all its contents recursively

FileUtils.rm_r("dir")
FileUtils.rm_r("file.cr")

[View source]
def rm_r(paths : Enumerable(String)) : Nil #

Deletes a list of files or directories paths If one path is a directory, this method removes all its contents recursively

FileUtils.rm_r(["dir", "file.cr"])

[View source]
def rm_rf(path : String) : Nil #

Deletes a file or directory path If path is a directory, this method removes all its contents recursively Ignore all errors.

FileUtils.rm_rf("dir")
FileUtils.rm_rf("file.cr")
FileUtils.rm_rf("non_existent_file")

[View source]
def rm_rf(paths : Enumerable(String)) : Nil #

Deletes a list of files or directories paths If one path is a directory, this method removes all its contents recursively Ignore all errors.

FileUtils.rm_rf(["dir", "file.cr", "non_existent_file"])

[View source]
def rmdir(path : String) : Nil #

Removes the directory at the given path. Alias of Dir.rmdir

FileUtils.rmdir("dir")

[View source]
def rmdir(paths : Enumerable(String)) : Nil #

Removes all directories at the given paths.

FileUtils.rmdir(["dir1", "dir2", "dir3"])

[View source]