File
Undocumented
-
Returns the pathname used to create file as a string. Does not normalize the name.
Declaration
Swift
public let path: String -
Returns the pathname used to create file as a string. Does not normalize the name. An alias to
File#path.Declaration
Swift
public var to_path: String -
Undocumented
-
Opens the file named by filename according to the given mode and returns a new
Fileobject.Declaration
Swift
public class func new(_ path: String, _ mode: String = "r", closure: ((File) -> ())? = nil) -> FileParameters
pathA file path.
modeA string represents the mode to open the file.
closureIf given, file would be closed automatically after closure executed.
Return Value
A file object.
-
Opens the file named by filename according to the given mode and returns a new
Fileobject.See also
An alias toFile#newDeclaration
Swift
public class func open(_ path: String, _ mode: String = "r", closure: ((File) -> ())? = nil) -> FileParameters
pathA file path.
modeA string represents the mode to open the file.
closureIf given, file would be closed automatically after closure executed.
Return Value
A file object.
-
Returns the last component of the filename given in
filename.File.basename("/home/work/file.swift") #=> "file.swift"If
suffixis given and present at the end offilename, it is removed.File.basename("/home/work/file.swift", ".swift") #=> "file"If
suffixis.*, any extension will be removed.File.basename("/home/work/file.swift", ".*") #=> "file" File.basename("/home/work/file.rb", ".*") #=> "file"Declaration
Swift
public class func basename(_ filename: String, _ suffix: String = "") -> StringParameters
filenameA file path string.
suffixA string will be removed from the filename.
Return Value
The last component with or without extension.
-
Returns all components of the filename given in
filenameexcept the last one.File.dirname("/home/work/file.swift") #=> "/home/work"Declaration
Swift
public class func dirname(_ filename: String) -> StringParameters
filenameA file path string.
Return Value
The directory of given filename.
-
Returns the extension (the portion of file name in path starting from the last period). If path is a dotfile, or starts with a period, then the starting dot is not dealt with the start of the extension.
An empty string will also be returned when the period is the last character in path.
Declaration
Swift
public class func extname(_ path: String) -> StringParameters
pathA file path.
Return Value
A file extension of empty string.
-
Converts a pathname to an absolute pathname. Relative paths are referenced from the current working directory of the process unless
diris given, in which case it will be used as the starting point. The given pathname may start with a~
, which expands to the process owner’s home directory (the environment variable HOME must be set correctly).File.expand(path: "~/file.swift") #=> "/absolute/path/to/home/file.swift" File.expand(path: "file.swift", in: "/usr/bin") #=> "/usr/bin/file.swift"Declaration
Swift
public class func expand(_ path: String, in dir: String? = nil) -> StringParameters
pathA file path.
dirA directory path.
Return Value
A absolute path.
-
Converts a pathname to an absolute pathname.
File.absolutePath("~/file.swift") #=> Dir.home + "/file.swift" File.absolutePath("./file.swift") #=> Dir.pwd + "/file.swift"Declaration
Swift
public class func absolutePath(_ path: String) -> StringParameters
pathA files path.
Return Value
A absolute path of given file path.
-
Splits the given string into a directory and a file component and returns a tuple with
(File.dirname, File.basename).File.split("/home/gumby/.profile") #=> ("/home/gumby", ".profile")Declaration
Swift
public class func split(_ path: String) -> (String, String)Parameters
pathA file path.
Return Value
A tuple with a directory and a file component.
-
Returns a new string formed by joining the strings using
/
.File.join("usr", "bin", "swift") #=> "usr/bin/swift"Declaration
Swift
public class func join(_ paths: String...) -> StringParameters
pathsAn array of file path.
Return Value
A new file path.
-
Returns true if stat is a regular file (not a device file, pipe, socket, etc.).
Declaration
Swift
public class func isFile(_ path: String) -> BoolParameters
pathA file path.
Return Value
A bool value.
-
Returns true if the named file is a directory, and false otherwise.
Declaration
Swift
public class func isDirectory(_ path: String) -> BoolReturn Value
A bool value.
-
Returns true if the named file is executable.
File.isExecutable("file.sh")Declaration
Swift
public class func isExecutable(_ path: String) -> BoolParameters
pathA file path.
Return Value
A bool value.
-
Returns true if the named file is readable.
File.isReadable("file.swift")Declaration
Swift
public class func isReadable(_ path: String) -> BoolParameters
pathA file path.
Return Value
A bool value.
-
Returns true if the named file is writable.
File.isWritable("file.rb")Declaration
Swift
public class func isWritable(_ path: String) -> BoolParameters
pathA file path.
Return Value
A bool value.
-
Returns true if the named file is deletable.
File.isDeletable("file.py")Declaration
Swift
public class func isDeletable(_ path: String) -> BoolParameters
pathA file path.
Return Value
A bool value.
-
Returns true if the named file exists, and false otherwise.
File.isExist("file.exs")Declaration
Swift
public class func isExist(_ path: String) -> BoolParameters
pathA file path.
Return Value
A bool value.
-
Changes permission bits on the named file(s) to the bit pattern represented by
mode.File.chmod(0o777, "file.swift")Declaration
Swift
public class func chmod(_ mode: Int, _ paths: String...) -> IntParameters
modeA permission bits.
pathsAn array of file path.
Return Value
The number of files processed.
-
Returns the file size of the named file.
File.size("somefile") #=> 1234 File.size("emptyfile") #=> 0Declaration
Swift
public class func size(_ path: String) -> IntParameters
pathA file path.
Return Value
The size of file.
-
Returns the last access time for the named file as a
Dateobject.Declaration
Swift
public class func atime(_ path: String) -> DateParameters
pathA file path.
Return Value
The atime of file.
-
Returns the birth time for the named file.
Declaration
Swift
public class func birthtime(_ path: String) -> DateParameters
pathA file path.
Return Value
The birthtime of file.
-
Returns true if the named file is a block device.
Declaration
Swift
public class func isBlockDev(_ path: String) -> BoolParameters
pathA file path.
Return Value
A bool value.
-
Returns true if the named file is a character device.
Declaration
Swift
public class func isCharDev(_ path: String) -> BoolParameters
pathA file path.
Return Value
A bool value.
-
Deletes the named files, returning the number of names passed as arguments.
Throws
FileManager#removeItem(atPath:)Declaration
Swift
public class func delete(_ paths: String...) throws -> IntParameters
pathsAn array of file path.
Return Value
The number of names passed as arguments.
-
Returns true if the named file exists and has a zero size.
Declaration
Swift
public class func isZero(_ path: String) -> BoolParameters
pathA file path.
Return Value
A bool value.
-
Identifies the type of the named file; the return string is one of
file
,directory
,characterSpecial
,blockSpecial
,fifo
,link
,socket
, orunknown
.Declaration
Swift
public class func ftype(_ path: String) -> StringParameters
pathA file path.
Return Value
A string describes the ftype.
View on GitHub
File Class Reference