@@ -6,41 +6,173 @@ from std/private/osdirs import dirExists, createDir, existsOrCreateDir, removeDi
6
6
7
7
export PathComponent
8
8
9
- proc dirExists * (dir: Path ): bool {.tags : [ReadDirEffect ].} =
9
+ proc dirExists * (dir: Path ): bool {.inline , tags : [ReadDirEffect ].} =
10
+ # # Returns true if the directory `dir` exists. If `dir` is a file, false
11
+ # # is returned. Follows symlinks.
10
12
result = dirExists (dir.string )
11
13
12
- proc createDir * (dir: Path ) {.tags : [WriteDirEffect , ReadDirEffect ].} =
14
+ proc createDir * (dir: Path ) {.inline , tags : [WriteDirEffect , ReadDirEffect ].} =
15
+ # # Creates the `directory`:idx: `dir`.
16
+ # #
17
+ # # The directory may contain several subdirectories that do not exist yet.
18
+ # # The full path is created. If this fails, `OSError` is raised.
19
+ # #
20
+ # # It does **not** fail if the directory already exists because for
21
+ # # most usages this does not indicate an error.
22
+ # #
23
+ # # See also:
24
+ # # * `removeDir proc`_
25
+ # # * `existsOrCreateDir proc`_
26
+ # # * `copyDir proc`_
27
+ # # * `copyDirWithPermissions proc`_
28
+ # # * `moveDir proc`_
13
29
createDir (dir.string )
14
30
15
- proc existsOrCreateDir * (dir: Path ): bool {.tags : [WriteDirEffect , ReadDirEffect ].} =
31
+ proc existsOrCreateDir * (dir: Path ): bool {.inline , tags : [WriteDirEffect , ReadDirEffect ].} =
32
+ # # Checks if a `directory`:idx: `dir` exists, and creates it otherwise.
33
+ # #
34
+ # # Does not create parent directories (raises `OSError` if parent directories do not exist).
35
+ # # Returns `true` if the directory already exists, and `false` otherwise.
36
+ # #
37
+ # # See also:
38
+ # # * `removeDir proc`_
39
+ # # * `createDir proc`_
40
+ # # * `copyDir proc`_
41
+ # # * `copyDirWithPermissions proc`_
42
+ # # * `moveDir proc`_
16
43
result = existsOrCreateDir (dir.string )
17
44
18
45
proc removeDir * (dir: Path , checkDir = false
19
- ) {.tags : [WriteDirEffect , ReadDirEffect ].} =
46
+ ) {.inline , tags : [WriteDirEffect , ReadDirEffect ].} =
47
+ # # Removes the directory `dir` including all subdirectories and files
48
+ # # in `dir` (recursively).
49
+ # #
50
+ # # If this fails, `OSError` is raised. This does not fail if the directory never
51
+ # # existed in the first place, unless `checkDir` = true.
52
+ # #
53
+ # # See also:
54
+ # # * `tryRemoveFile proc`_
55
+ # # * `removeFile proc`_
56
+ # # * `existsOrCreateDir proc`_
57
+ # # * `createDir proc`_
58
+ # # * `copyDir proc`_
59
+ # # * `copyDirWithPermissions proc`_
60
+ # # * `moveDir proc`_
20
61
removeDir (dir.string , checkDir)
21
62
22
- proc moveDir * (source, dest: Path ) {.tags : [ReadIOEffect , WriteIOEffect ].} =
63
+ proc moveDir * (source, dest: Path ) {.inline , tags : [ReadIOEffect , WriteIOEffect ].} =
64
+ # # Moves a directory from `source` to `dest`.
65
+ # #
66
+ # # Symlinks are not followed: if `source` contains symlinks, they themself are
67
+ # # moved, not their target.
68
+ # #
69
+ # # If this fails, `OSError` is raised.
70
+ # #
71
+ # # See also:
72
+ # # * `moveFile proc`_
73
+ # # * `copyDir proc`_
74
+ # # * `copyDirWithPermissions proc`_
75
+ # # * `removeDir proc`_
76
+ # # * `existsOrCreateDir proc`_
77
+ # # * `createDir proc`_
23
78
moveDir (source.string , dest.string )
24
79
25
80
iterator walkPattern * (pattern: Path ): Path {.tags : [ReadDirEffect ].} =
81
+ # # Iterate over all the files and directories that match the `pattern`.
82
+ # #
83
+ # # On POSIX this uses the `glob`:idx: call.
84
+ # # `pattern` is OS dependent, but at least the `"*.ext"`
85
+ # # notation is supported.
86
+ # #
87
+ # # See also:
88
+ # # * `walkFiles iterator`_
89
+ # # * `walkDirs iterator`_
90
+ # # * `walkDir iterator`_
91
+ # # * `walkDirRec iterator`_
26
92
for p in walkPattern (pattern.string ):
27
93
yield Path (p)
28
94
29
95
iterator walkFiles * (pattern: Path ): Path {.tags : [ReadDirEffect ].} =
96
+ # # Iterate over all the files that match the `pattern`.
97
+ # #
98
+ # # On POSIX this uses the `glob`:idx: call.
99
+ # # `pattern` is OS dependent, but at least the `"*.ext"`
100
+ # # notation is supported.
101
+ # #
102
+ # # See also:
103
+ # # * `walkPattern iterator`_
104
+ # # * `walkDirs iterator`_
105
+ # # * `walkDir iterator`_
106
+ # # * `walkDirRec iterator`_
30
107
for p in walkFiles (pattern.string ):
31
108
yield Path (p)
32
109
33
110
iterator walkDirs * (pattern: Path ): Path {.tags : [ReadDirEffect ].} =
111
+ # # Iterate over all the directories that match the `pattern`.
112
+ # #
113
+ # # On POSIX this uses the `glob`:idx: call.
114
+ # # `pattern` is OS dependent, but at least the `"*.ext"`
115
+ # # notation is supported.
116
+ # #
117
+ # # See also:
118
+ # # * `walkPattern iterator`_
119
+ # # * `walkFiles iterator`_
120
+ # # * `walkDir iterator`_
121
+ # # * `walkDirRec iterator`_
34
122
for p in walkDirs (pattern.string ):
35
123
yield Path (p)
36
124
37
125
iterator walkDir * (dir: Path ; relative = false , checkDir = false ):
38
- tuple [kind: PathComponent , path: Path ] {.tags : [ReadDirEffect ].} =
39
- for (k, p) in walkDir (dir.string , relative, checkDir):
40
- yield (k, Path (p))
126
+ tuple [kind: PathComponent , path: Path ] {.tags : [ReadDirEffect ].} =
127
+ # # Walks over the directory `dir` and yields for each directory or file in
128
+ # # `dir`. The component type and full path for each item are returned.
129
+ # #
130
+ # # Walking is not recursive. If ``relative`` is true (default: false)
131
+ # # the resulting path is shortened to be relative to ``dir``.
132
+ # #
133
+ # # If `checkDir` is true, `OSError` is raised when `dir`
134
+ # # doesn't exist.
135
+ for (k, p) in walkDir (dir.string , relative, checkDir):
136
+ yield (k, Path (p))
41
137
42
138
iterator walkDirRec * (dir: Path ,
43
139
yieldFilter = {pcFile}, followFilter = {pcDir},
44
140
relative = false , checkDir = false ): Path {.tags : [ReadDirEffect ].} =
141
+ # # Recursively walks over the directory `dir` and yields for each file
142
+ # # or directory in `dir`.
143
+ # #
144
+ # # If ``relative`` is true (default: false) the resulting path is
145
+ # # shortened to be relative to ``dir``, otherwise the full path is returned.
146
+ # #
147
+ # # If `checkDir` is true, `OSError` is raised when `dir`
148
+ # # doesn't exist.
149
+ # #
150
+ # # .. warning:: Modifying the directory structure while the iterator
151
+ # # is traversing may result in undefined behavior!
152
+ # #
153
+ # # Walking is recursive. `followFilter` controls the behaviour of the iterator:
154
+ # #
155
+ # # ===================== =============================================
156
+ # # yieldFilter meaning
157
+ # # ===================== =============================================
158
+ # # ``pcFile`` yield real files (default)
159
+ # # ``pcLinkToFile`` yield symbolic links to files
160
+ # # ``pcDir`` yield real directories
161
+ # # ``pcLinkToDir`` yield symbolic links to directories
162
+ # # ===================== =============================================
163
+ # #
164
+ # # ===================== =============================================
165
+ # # followFilter meaning
166
+ # # ===================== =============================================
167
+ # # ``pcDir`` follow real directories (default)
168
+ # # ``pcLinkToDir`` follow symbolic links to directories
169
+ # # ===================== =============================================
170
+ # #
171
+ # #
172
+ # # See also:
173
+ # # * `walkPattern iterator`_
174
+ # # * `walkFiles iterator`_
175
+ # # * `walkDirs iterator`_
176
+ # # * `walkDir iterator`_
45
177
for p in walkDirRec (dir.string , yieldFilter, followFilter, relative, checkDir):
46
178
yield Path (p)
0 commit comments