Dir
Undocumented
-
Returns the path parameter passed to dir’s constructor.
Declaration
Swift
public let path: String -
Returns the file descriptor used in dir. This method uses
dirfd()function defined by POSIX 2008.Declaration
Swift
public var fileno: Int -
Returns the current position in dir. See also
Dir#seek(pos:).Declaration
Swift
public var pos: Int -
Returns the current position in dir.
Declaration
Swift
public var tell: Int -
Returns the path parameter passed to dir’s constructor.
Declaration
Swift
public var to_path: String -
Return a string describing this Dir object.
Declaration
Swift
public var inspect: String -
Return a string describing this Dir object.
Declaration
Swift
public var description: String -
Returns a new directory object for the named directory.
Declaration
Swift
public init?(_ path: String) -
Returns a new directory object for the named directory.
Declaration
Swift
public static func new(_ path: String) -> Dir?Parameters
pathA directory path.
Return Value
A new
Dirobject or nil. -
Returns a new directory object for the named directory.
Declaration
Swift
public static func open(_ path: String) -> Dir?Parameters
pathA directory path.
Return Value
A new
Dirobject or nil. -
Returns the path to the current working directory of this process as a string.
Declaration
Swift
public static var getwd: String -
Returns the path to the current working directory of this process as a string. An alias to
Dir#getwdvar.Declaration
Swift
public static var pwd: String -
Returns the home directory of the current user or the named user if given.
Dir.home #=> "/Users/username"Declaration
Swift
public static var home: String -
Declaration
Swift
public enum HomeDirectory: Error -
Returns the home directory of the current user or the named user if given.
Dir.home() #=> "/Users/username" Dir.home("user") #=> "/user"Throws
HomeDirectory.notExists if user doesn’t exist.Declaration
Swift
public static func home(_ user: String? = nil) throws -> StringParameters
pathThe name of user.
Return Value
Home directory.
-
Changes the current working directory of the process to the given string.
Dir.chdir("/var/spool/mail") Dir.pwd #=> "/var/spool/mail"Declaration
Swift
public static func chdir(_ path: String = "~") -> BoolParameters
pathA new current working directory.
Return Value
A bool indicates the result of
Dir#chdir(path:) -
Changes this process’s idea of the file system root.
See also
Darwin.chroot.Declaration
Swift
public static func chroot(_ path: String) -> BoolParameters
pathA directory path.
Return Value
A bool value indicates the result of
Darwin.chroot -
Changes the current working directory of the process to the given string. Block is passed the name of the new current directory, and the block is executed with that as the current directory. The original working directory is restored when the block exits. The return value of chdir is the value of the block.
Dir.pwd #=> "/work" let value = Dir.chdir("/var") { Dir.pwd #=> "/var" return 1 } Dir.pwd #=> "/work" value #=> 1Declaration
Swift
public static func chdir<T>(_ path: String = "~", closure: ((Void) -> T)) -> TParameters
pathA new current working directory.
closureA block executed in target directory.
Return Value
The value of the closure.
-
Makes a new directory named by string, with permissions specified by the optional parameter anInteger.
try Dir.mkdir("draveness") try! Dir.mkdir("draveness/spool/mail", recursive: true)Throws
WhenFileManager#createDirectory(atPath:withIntermediateDirectories:attributes:)throws.Declaration
Swift
public static func mkdir(_ path: String, recursive: Bool = false, _ permissions: Int? = nil) throwsParameters
pathA new directory path.
recursiveWhether creats intermeidate directories.
permissionsAn integer represents the posix permission.
-
Error throws when called
Dir#rmdir(path:)method.- notEmpty: Directory is not empty.
- notExists: Directory is not exists.
Declaration
Swift
public enum RemoveDirectoryError: Error -
Deletes the named directory.
try Dir.rmdir("/a/folder/path")Throws
RemoveDirectoryErrorif the directory isn’t empty.Declaration
Swift
public static func rmdir(_ path: String) throwsParameters
pathA directory path
-
Deletes the named directory. An alias to
Dir.rmdir(path:).try Dir.unlink("/a/folder/path")Throws
RemoveDirectoryErrorif the directory isn’t empty.Declaration
Swift
public static func unlink(_ path: String) throwsParameters
pathA directory path
-
Returns true if the named file is a directory, false otherwise.
Dir.isExist("/a/folder/path/not/exists") #=> false Dir.isExist("/a/folder/path/exists") #=> trueDeclaration
Swift
public static func isExist(_ path: String) -> BoolParameters
pathA file path.
Return Value
A bool value indicates whether there is a directory in given path.
-
Returns true if the named file is an empty directory, false if it is not a directory or non-empty.
Dir.isEmpty("/a/empty/folder") #=> true Dir.isEmpty("/a/folder/not/exists") #=> true Dir.isEmpty("/a/folder/with/files") #=> falseDeclaration
Swift
public static func isEmpty(_ path: String) -> BoolParameters
pathA directory path.
Return Value
A bool value indicates the directory is not exists or is empty.
-
Returns an array containing all of the filenames in the given directory. Will return an empty array if the named directory doesn’t exist.
Declaration
Swift
public static func entries(_ path: String) -> [String]Parameters
pathA directory path.
Return Value
An array of all filenames in the given directory.
-
Calls the block once for each entry in the named directory, passing the filename of each entry as a parameter to the block.
Declaration
Swift
public static func foreach(_ path: String, closure: (String) -> ())Parameters
pathA directory path.
closureA closure accepts all the entries in current directory.
-
Deletes the named directory.
Declaration
Swift
public static func delete(_ path: String) -> BoolParameters
pathA directory path.
Return Value
A bool value indicates the result of
Dir.delete(path:) -
Seeks to a particular location in dir.
Declaration
Swift
public func seek(_ pos: Int)Parameters
posA particular location.
-
Repositions dir to the first entry.
Declaration
Swift
public func rewind()
View on GitHub
Dir Class Reference