File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed
Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change 1+ import argparse
2+ import os
3+
4+ def show_unhidden_files (listDir ):
5+ for file in listDir :
6+ if not file .startswith ('.' ):
7+ print (file )
8+ def show_all_files (listDir ):
9+ for file in listDir :
10+ print (file )
11+
12+
13+ parser = argparse .ArgumentParser (
14+ prog = "my-ls" ,
15+ description = "Simple ls clone with -a and -l options" ,
16+ )
17+
18+ parser .add_argument ("-a" , action = "store_true" , help = "include hidden files" )
19+ parser .add_argument ("-1" , dest = "one" ,action = "store_true" , help = "use a long listing format" )
20+ parser .add_argument ("path" , nargs = "?" , default = "." , help = "The directory to list" )
21+ args = parser .parse_args ()
22+
23+
24+
25+
26+
27+ fn = args .path
28+ listDir = os .listdir (fn )
29+ if fn != "" :
30+ if args .a and args .one :
31+ show_all_files (listDir )
32+ elif args .a :
33+ show_all_files (listDir )
34+ elif args .one :
35+ show_unhidden_files (listDir )
36+
37+ else :
38+ show_unhidden_files (listDir )
39+
You can’t perform that action at this time.
0 commit comments