3 //doc
Directory with(aPath
) Returns a new instance with the provided path
.")
4 with := method(path, self clone setPath(path))
6 createIfAbsent := method(if(self exists not, self create); self)
8 parentDirectory := method(
9 if(path == ".", return nil)
10 p := self path pathComponent
12 Directory clone setPath(p)
16 items select(item, item type ==("Directory") and(item name != ".") and(item name != ".."))
19 isAccessible := method(
22 e catch(Exception, r = false)
29 while(d = d parentDirectory, list append(d))
33 accessibleParents := method(parents select(isAccessible))
35 files := method(items select(type == "File"))
37 fileNames := method(files mapInPlace(name))
39 fileNamed := method(name,
40 //files detect(i, v, v name == name)
41 File clone setPath(Path with(path, name))
44 filesWithExtension := method(ext,
45 if(ext containsSeq(".") not, ext = "." .. ext)
46 files select(f, f name endsWithSeq(ext))
49 folderNamed := method(name,
50 folders detect(i, v, v name == name)
54 File clone setPath(self path) remove
57 folderNamedCreateIfAbsent := method(name,
58 f := folderNamed(name)
60 createSubdirectory(name)
64 createFileNamed := method(name,
67 return File clone setPath(Path with(path, name))
70 moveTo := method(path,
71 File with(self path) moveTo(path)