Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jan 23, 2019. It is now read-only.

Commit 49ae3e5

Browse files
author
js-d-coder
committed
refactor createFileList function to remove redundancy
1 parent 7295fc1 commit 49ae3e5

File tree

1 file changed

+17
-26
lines changed

1 file changed

+17
-26
lines changed

‎lsi‎

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def version():
7171
"""Print version, license and exit"""
7272
if args.version:
7373
print(
74-
"""lsi version 1.1.0
74+
"""lsi version 1.1.1
7575
7676
Copyright (c) 2017 js-d-coder (www.github.com/js-d-coder)
7777
@@ -100,34 +100,25 @@ THE SOFTWARE.
100100

101101
def createFileList(dirname):
102102
"""create list of files in given directory based on various options"""
103-
dirContents = []
104-
all = os.listdir(dirname)
103+
files = []
104+
dirs = []
105+
all_files = os.listdir(dirname)
106+
105107
if args.non_hidden:
106-
if args.only_files:
107-
dirContents = [file for file in all if not os.path.isdir(dirname + "/" + file) and file[0] != '.' ]
108-
elif args.only_dir:
109-
dirContents = [file+"/" for file in all if os.path.isdir(dirname + "/" + file) and file[0] != '.' ]
110-
else:
111-
dirContents = [file for file in all if not os.path.isdir(dirname + "/" + file) and file[0] != '.' ]
112-
dirContents += [file+"/" for file in all if os.path.isdir(dirname + "/" + file) and file[0] != '.' ]
108+
files = [file for file in all_files if not os.path.isdir(dirname + "/" + file) and file[0] != '.' ]
109+
dirs = [file+"/" for file in all_files if os.path.isdir(dirname + "/" + file) and file[0] != '.' ]
113110
elif args.hidden:
114-
if args.only_files:
115-
dirContents = [file for file in all if not os.path.isdir(dirname + "/" + file) and file[0] == '.' ]
116-
elif args.only_dir:
117-
dirContents = [file+"/" for file in all if os.path.isdir(dirname + "/" + file) and file[0] == '.' ]
118-
else:
119-
dirContents = [file for file in all if not os.path.isdir(dirname + "/" + file) and file[0] == '.' ]
120-
dirContents += [file+"/" for file in all if os.path.isdir(dirname + "/" + file) and file[0] == '.' ]
111+
files = [file for file in all_files if not os.path.isdir(dirname + "/" + file) and file[0] == '.' ]
112+
dirs = [file+"/" for file in all_files if os.path.isdir(dirname + "/" + file) and file[0] == '.' ]
121113
else:
122-
if args.only_files:
123-
dirContents = [file for file in all if not os.path.isdir(dirname + "/" + file)]
124-
elif args.only_dir:
125-
dirContents = [file+"/" for file in all if os.path.isdir(dirname + "/" + file)]
126-
else:
127-
dirContents = [file for file in all if not os.path.isdir(dirname + "/" + file)]
128-
dirContents += [file+"/" for file in all if os.path.isdir(dirname + "/" + file)]
129-
return dirContents
130-
114+
files = [file for file in all_files if not os.path.isdir(dirname + "/" + file)]
115+
dirs = [file+"/" for file in all_files if os.path.isdir(dirname + "/" + file)]
116+
if args.only_files:
117+
return files
118+
elif args.only_dir:
119+
return dirs
120+
else:
121+
return files + dirs
131122

132123
def xargsInput():
133124
"""create string of null terminated file names for processing by xargs command"""

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /