blob: 1cf561c22e51a10d028dc8df11799375cfa081f7 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
#
#
# Nim's Runtime Library
# (c) Copyright 2015 Andreas Rumpf
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
#
## Compile-time only version for walkDir if you need it at compile-time
## for JavaScript.
type
PathComponent* = enum ## Enumeration specifying a path component.
pcFile, ## path refers to a file
pcLinkToFile, ## path refers to a symbolic link to a file
pcDir, ## path refers to a directory
pcLinkToDir ## path refers to a symbolic link to a directory
proc staticWalkDir(dir: string; relative: bool): seq[
tuple[kind: PathComponent; path: string]] =
discard
iterator walkDir*(dir: string; relative = false): tuple[kind: PathComponent;
path: string] =
for k, v in items(staticWalkDir(dir, relative)):
yield (k, v)
iterator walkDirRec*(dir: string; filter = {pcFile, pcDir}): string =
var stack = @[dir]
while stack.len > 0:
for k, p in walkDir(stack.pop()):
if k in filter:
case k
of pcFile, pcLinkToFile: yield p
of pcDir, pcLinkToDir: stack.add(p)
|