module Dir
Directories, and the current directory. Operating-system failures raise
SystemCallError. The operations that read or change the file system
run on a helper thread: only the calling task waits.
dir = File.join(Dir.tmpdir, "doc_dir_#{Process.pid}")
Dir.mkdir_p(File.join(dir, "src"))
File.write(File.join(dir, "src", "main.qz"), "")
File.write(File.join(dir, "README"), "")
Dir.children(dir) # => ["README", "src"]
Dir.glob("**/*.qz", dir) # => ["src/main.qz"]
Dir.rm_rf(dir)
Dir.exist?(dir) # => false
<prelude>:6396
Class methods
def self.pwd -> String
The current directory, as an absolute path.
<prelude>:6398
def self.getwd -> String
The current directory (as .pwd).
<prelude>:6400
def self.home -> String
The home directory, from the HOME environment variable.
Raises
ArgumentError when HOME is not set.
<prelude>:6406
def self.tmpdir -> String
The directory for temporary files: the TMPDIR environment variable,
or /tmp.
<prelude>:6409
def self.chdir(path: String) -> Int
Makes path the current directory; returns 0.
WARNING: The current directory belongs to the process: changing it changes it for every task.
<prelude>:6414
def self.chdir[R](path: String, &: (String) -> R) -> R
Makes path the current directory while the block runs, yielding
path, then restores the previous one (also when the block raises);
returns the block's value. The change is seen by every task meanwhile.
<prelude>:6418
def self.exist?(path: String) -> Bool
Whether path is a directory.
<prelude>:6420
def self.empty?(path: String) -> Bool
Whether path is a directory with no entries; false when it is not a
directory or cannot be read.
<prelude>:6423
def self.mkdir(path: String) -> Int
Creates the directory path (its parent must exist); returns 0.
Raises
SystemCallError when it exists or cannot be made.
<prelude>:6429
def self.mkdir_p(path: String) -> Int
Creates the missing parents too (mkdir -p).
Returns 0, also when the directory already exists.
<prelude>:6433
def self.rmdir(path: String) -> Int
Removes the empty directory path; returns 0.
Raises
SystemCallError when it is missing or not empty.
<prelude>:6439
def self.rm_rf(path: String) -> Int
Removes a directory and everything in it (rm -rf).
Returns 0, also when nothing is at path.
<prelude>:6443
def self.entries(path: String) -> Array[String]
The names in the directory path, sorted, with "." and ".."
first.
<prelude>:6446
def self.children(path: String) -> Array[String]
The names in the directory path, sorted, without "." and "..".
<prelude>:6448
def self.each_child(path: String, &: (String) -> Void) -> Void
Yields each name .children returns.
<prelude>:6450
def self.glob(pattern: String, base: String? = …) -> Array[String]
The paths matching pattern: *, ?, [...], ** and {a,b};
the results are sorted.
With base, a relative pattern is matched in that directory and the
paths are relative to it; without, in the current directory. *
matches names starting with a dot too, unlike Ruby's.
Raises
ArgumentError for a malformed pattern ("[").
<prelude>:6461
def self.glob(patterns: Array[String], base: String? = …) -> Array[String]
The paths matching any of patterns, sorted, each once.
<prelude>:6463