recursion

This commit is contained in:
Kyle Brown 2020-12-25 07:44:05 -08:00
parent 6e95741e9e
commit fbf6b9ff9a

View file

@ -2,7 +2,7 @@ let doc = """
Renamer.
Usage:
renamer <path>... [--season=<se>] [--bash] [--log]
renamer <path>... [--season=<se>] [--bash] [--log] [--recurse]
renamer (-h | --help)
renamer [--version]
@ -12,6 +12,7 @@ Options:
--season=<se> Season of show. [Default is 01]
-b, --bash Prints output that can be piped to bash
-l, --log Enables logging
-r, --recurse Enables recursive finding of files
"""
@ -116,10 +117,15 @@ proc main() =
file_list = initDoublyLinkedList[string]()
season: string
bash: bool
recurse: bool
fromDir: string
toDir: string
let args = docopt(doc, version = "Renamer 0.1")
let path = args["<path>"]
if args["--season"]: season = $args["--season"]
if args["--bash"]: bash = parseBool($args["--bash"])
if args["--recurse"]: recurse = parseBool($args["--recurse"])
# Builds file list up to 1 directory deep. Last option is the output dir
for i, c in path:
@ -127,15 +133,14 @@ proc main() =
if not c.isDir:
file_list.append(c.join)
else: # Is a dir, walk and add files
for kind, path in walkDir(c):
if not path.isDir: file_list.append(path)
if not recurse:
for kind, path in walkDir(c):
if not path.isDir: file_list.append(path)
else: # recursive
for x in walkDirRec(c):
if not isDir(x): file_list.append(x)
else: toDir = c
if args["--season"]:
season = $args["--season"]
if args["--bash"]:
bash = parseBool($args["--bash"])
if not isatty(stdin):
while true:
try: