fs/dir
Creating, listing, copying, moving and removing directories.
import fs.dir
The fs.dir package covers everything you do with directories. When a function fails it records the detail in the os.error package.
Note that Exists here is true only for a directory; for files use fs.file.Exists.
Functions
Mkdir
func Mkdir(p: str): intimport fs.dir
import fs.file
func main:
dir.Mkdir("library")
dir.MkdirAll("library/poetry/hafez")
file.WriteText("library/index.txt", "3 books")
file.WriteText("library/poetry/hafez/ghazal.txt", "a line of verse")
println dir.Exists("library"), dir.IsDir("library/index.txt")
println dir.List("library").len(), dir.ListDirs("library"), dir.ListFiles("library")
println dir.Walk("library").len(), dir.Size("library") > 0
println dir.Permissions("library") > 0, dir.ModTime("library") > 0
dir.Copy("library", "backup")
dir.Move("backup", "archive")
println dir.Exists("backup"), dir.Exists("archive/poetry/hafez"), file.Exists("archive/poetry/hafez/ghazal.txt")
dir.Mkdir("empty")
dir.Remove("empty")
dir.RemoveAll("library")
dir.RemoveAll("archive")
println dir.Exists("library"), dir.Exists("empty")
endMkdirAll
func MkdirAll(p: str): intThe example for this item is shown with the ones above: fs-dir-List.salam
Remove
func Remove(p: str): intThe example for this item is shown with the ones above: fs-dir-List.salam
RemoveAll
func RemoveAll(p: str): intThe example for this item is shown with the ones above: fs-dir-List.salam
List
func List(p: str): Vector<str>The example for this item is shown with the ones above: fs-dir-List.salam
ListDirs
func ListDirs(p: str): Vector<str>The example for this item is shown with the ones above: fs-dir-List.salam
ListFiles
func ListFiles(p: str): Vector<str>The example for this item is shown with the ones above: fs-dir-List.salam
Walk
func Walk(p: str): Vector<str>The example for this item is shown with the ones above: fs-dir-List.salam
Copy
func Copy(src: str, dst: str): intThe example for this item is shown with the ones above: fs-dir-List.salam
Move
func Move(src: str, dst: str): intThe example for this item is shown with the ones above: fs-dir-List.salam
Exists
func Exists(p: str): boolThe example for this item is shown with the ones above: fs-dir-List.salam
IsDir
func IsDir(p: str): boolThe example for this item is shown with the ones above: fs-dir-List.salam
Size
func Size(p: str): i64The example for this item is shown with the ones above: fs-dir-List.salam
Permissions
func Permissions(p: str): intThe example for this item is shown with the ones above: fs-dir-List.salam
ModTime
func ModTime(p: str): i64The example for this item is shown with the ones above: fs-dir-List.salam