File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22from os import listdir
33
44parser = argparse .ArgumentParser (prog = "ls" , description = "List directory contents. Ignore files and directories starting with a '.' by default" )
5- parser .add_argument ("-1" , help = "List one file per line." , action = "store_true" )
5+ parser .add_argument ("-1" , dest = "one" , help = "List one file per line." , action = "store_true" )
66parser .add_argument ("-a" , help = "Do not ignore hidden files (files with names that start with '.')." , action = "store_true" )
77parser .add_argument ("path" , help = "The directory path (optional)." , default = "." , nargs = "?" )
88
1111path = args .path
1212
1313show_hidden = args .a
14+ one_per_line = args .one
1415
1516contents = []
1617
1920 contents .append (f )
2021 if show_hidden == True :
2122 contents .append (f )
22-
23- print (" " .join (contents ))
23+
24+ contents .sort ()
25+
26+ if one_per_line == True :
27+ print ("\n " .join (contents ))
28+ else :
29+ print (" " .join (contents ))
You can’t perform that action at this time.
0 commit comments