summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@jvnv.net>2010-09-11 19:44:52 +0200
committerVegard Storheil Eriksen <zyp@jvnv.net>2010-09-11 19:44:52 +0200
commit8a7ddb39932fd34a2cae5fc556c1644244343ff2 (patch)
tree73b0f238978612d25a33c7ff39433a68500cd262
parente890c121465333d48662be879db441e552281920 (diff)
Skipping hidden files and directories while searching recursively.
-rwxr-xr-xanidb17
1 files 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.')