From d10da5a150dbc78370eea7c06f331cf59d3d68c6 Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Sat, 11 Sep 2010 19:44:52 +0200 Subject: Skipping hidden files and directories while searching recursively. --- anidb | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/anidb b/anidb index 81f6850..079bc07 100755 --- a/anidb +++ b/anidb @@ -6,6 +6,7 @@ warnings.filterwarnings('ignore', 'Python C API version mismatch for module _mul import pyanidb, pyanidb.hash import ConfigParser, optparse, os, sys, getpass +from collections import deque # Colors. @@ -81,7 +82,9 @@ if options.login: # Input files. files = [] -for name in args: +remaining = deque(args) +while remaining: + name = remaining.popleft() if not os.access(name, os.R_OK): print red('Invalid file:'), name elif os.path.isfile(name): @@ -90,10 +93,14 @@ for name in args: if not options.recursive: print red('Is a directory:'), name else: - for root, subdirs, subfiles in os.walk(name): - subdirs.sort() - subfiles.sort() - files += [os.path.join(root, file) for file in subfiles if True in [file.endswith('.' + suffix) for suffix in options.suffix]] + for sub in sorted(os.listdir(name)): + if sub.startswith('.'): + continue + sub = os.path.join(name, sub) + if os.path.isfile(name) and any(sub.endswith('.' + suffix) for suffix in options.suffix): + files.append(sub) + elif os.path.isdir(sub): + remaining.appendleft(sub) if not files: print blue('Nothing to do.') -- cgit v1.2.3