File.Entry
type File.Entry = { name: string, isDir: bool, isSymlink: bool }File.Entry is one entry of a directory, as File.readDir reports it. name is the entry's name, without the directory. isDir and isSymlink describe the entry itself and not what a link points to: a symbolic link has isSymlink true and isDir false, also when it points to a directory, and File.stat of its path tells what it points to.
Details
nameis the entry's name alone, as File.list gives it. Join it to the directory withPath.jointo get a path.isDirandisSymlinkare never both true: a symbolic link is a link, whatever it points to.- A
File.Entryhas no size, time, or mode; File.stat has those, as a File.Info.
Basic examples
Get the entries of a directory with File.readDir and read their fields:
for entry in try File.readDir("notes") {
println("${entry.name} ${entry.isDir} ${entry.isSymlink}")
}archive true false
todo.txt false falseScope
A File.Entry is a record, so it destructures and compares as one:
let entry = (try File.readDir("inbox"))[0]
let { name, isDir } = entry
println(name)
println(isDir)
println(entry == File.Entry{ name: "todo.txt", isDir: false, isSymlink: false })todo.txt
false
trueA File.Entry prints as a record:
println((try File.readDir("shelf"))[0])File.Entry{ name: "archive", isDir: true, isSymlink: false }Properties and relations
A File.Entry holds the three fields of the same names that a File.Info has when File.stat is told not to follow a link:
try File.symlink("archive", "desk/old")
for entry in try File.readDir("desk") {
let info = try File.stat(Path.join(["desk", entry.name]), follow: false)
assert(entry.name == info.name)
assert(entry.isDir == info.isDir)
assert(entry.isSymlink == info.isSymlink)
}Possible issues
isDir is false for a link to a directory. Ask File.stat, which follows the link, what it points to:
try File.mkdir("shortcuts/sub")
try File.symlink("sub", "shortcuts/to-dir")
let entry = (try File.readDir("shortcuts")).find({ x.name == "to-dir" })
println(entry?.isDir)
println((try File.stat("shortcuts/to-dir")).isDir)false
truename is not a path. Join it to the directory with Path.join before you read or stat the entry, as the same issue on File.readDir shows.
See also
- File.readDir: the entries of a directory
- File.list: the names alone
- File.Info: what File.stat reports of one path
- Path.join: the path of an entry, from the directory and its name
