You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Easy way to work with files, directories and paths in swift on macOS and linux.
Why?
You are developing a cli and you want to:
Read/Write files.
Create/Delete files.
Create/Delete/List directories.
Get different paths (Home/Current/Temp).
Get the base name and directory name of a path
You can use FileUtils with Guaka to create aweseome command line applications.
Note: At the moment, this library only deals with textual files contents. (Check todo section of this file).
Usage
File
Create a file
File(path: path, fileMode:.write)
// or
File.create(path: path)
Delete a file
File.delete(atPath: path)
Read file content
letcontent=File.read(atPath: path)
// or
letcontent=String.read(contentsOfFile: path)
Write file content
File.write(string:"ABCDEF", toPath: path,)
// or
"AAAAA".write(toFile: path)
Check if file exists
File.exists(path)
Path
Get temporary file and directory
lettmp=Path.tempPath
// or
lettmp=Path.tempFile
// or
lettmp=Path.tempFileName(withName:"abc.txt")
Get the current directory
letpath=Path.currentDirectory
Get the home directory
letpath=Path.home
Check if the path exists
letexists=Path.exists(path)
Check the type of the file at a path
lettype=Path.type(ofPath: path)
type is a member of the PathType enum. This enum defines directory, executable, link and file
Expand a tilde in the path
letexpanded=Path.expand("~/Documents")
// expanded is "/Users/YourUser/Documents"
Get the base name and the directory name of a path
letbase=Path.baseName(forPath:"/Documents/this/is/mypath")
// base is "mypath"
letdir=Path.dirName(forPath:"/Documents/this/is/mypath")
// dir is "/Documents/this/is"