New doc system done for core
[io.git] / libs / iovm / io / Directory.io
blobec9a22745d53ee1b4476800f3f1c9b1e53996011
2 Directory do(
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
11 if(p == "", p = ".")
12 Directory clone setPath(p)
15 folders := method(
16 items select(item, item type ==("Directory") and(item name != ".") and(item name != ".."))
19 isAccessible := method(
20 r := true
21 e := try(items)
22 e catch(Exception, r = false)
26 parents := method(
27 list := List clone
28 d := self
29 while(d = d parentDirectory, list append(d))
30 list reverse
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)
53 remove := method(
54 File clone setPath(self path) remove
57 folderNamedCreateIfAbsent := method(name,
58 f := folderNamed(name)
59 if(f, return f)
60 createSubdirectory(name)
61 folderNamed(name)
64 createFileNamed := method(name,
65 f := fileNamed(name)
66 if(f, return f)
67 return File clone setPath(Path with(path, name))
70 moveTo := method(path,
71 File with(self path) moveTo(path)
72 self