File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33import sys
44import glob
5- import os
5+
66
77def expand_paths (paths ):
88 """Expand glob patterns and return sorted unique file list."""
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python3
2+
3+ import sys
4+ import os
5+
6+ def list_dir (path , show_all = False , one_per_line = False ):
7+ try :
8+ entries = os .listdir (path )
9+ except FileNotFoundError :
10+ print (f"ls: cannot access '{ path } ': No such file or directory" , file = sys .stderr )
11+ return
12+
13+ entries = sorted (entries )
14+
15+ if show_all :
16+ normal = sorted ([e for e in entries if not e .startswith ('.' )])
17+ hidden = sorted ([e for e in entries if e .startswith ('.' )])
18+
19+ entries = ["." , ".." ] + normal + hidden
20+ else :
21+ entries = sorted ([e for e in entries if not e .startswith ('.' )])
22+
23+ for entry in entries :
24+ print (entry )
25+
26+ def main ():
27+ args = sys .argv [1 :]
28+
29+ show_all = False
30+ one_per_line = False
31+ paths = []
32+
33+ for a in args :
34+ if a == "-a" :
35+ show_all = True
36+ elif a == "-1" :
37+ one_per_line = True
38+ else :
39+ paths .append (a )
40+
41+ if not paths :
42+ paths = ["." ]
43+
44+ for path in paths :
45+ list_dir (path , show_all , one_per_line )
46+
47+ if __name__ == "__main__" :
48+ main ()
You can’t perform that action at this time.
0 commit comments