|
1 | 1 | import os |
2 | 2 | import argparse |
3 | | -import sys |
4 | 3 |
|
5 | 4 | parser = argparse.ArgumentParser( |
6 | 5 | prog="ls", |
|
14 | 13 | args = parser.parse_args() |
15 | 14 |
|
16 | 15 | def arguments_proceeding(files): |
| 16 | + data_to_proceed = files |
| 17 | + |
| 18 | + if args.a: |
| 19 | + data_to_proceed = [f for f in files] |
| 20 | + data_to_proceed.sort() |
| 21 | + data_to_proceed.insert(0, "..") |
| 22 | + data_to_proceed.insert(0, ".") |
| 23 | + else: |
| 24 | + data_to_proceed = [f for f in files if not f.startswith('.')] |
| 25 | + data_to_proceed.sort(key=str.lower) |
17 | 26 | if args.one: |
18 | | - files.sort() |
19 | | - for f in files: |
| 27 | + output = [f for f in data_to_proceed] |
| 28 | + for f in output: |
20 | 29 | print(f) |
| 30 | + else: |
| 31 | + print(" ".join(data_to_proceed)) |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | + |
21 | 45 |
|
22 | | - if not args.a: |
23 | | - files = [f for f in files if not f.startswith(".")] |
24 | 46 |
|
25 | 47 |
|
| 48 | + |
| 49 | + |
| 50 | + |
| 51 | +# output = files |
| 52 | + |
| 53 | +# # if args.one: |
| 54 | +# # files.sort() |
| 55 | +# # for f in files: |
| 56 | +# # print(f) |
| 57 | + |
| 58 | +# if args.a: |
| 59 | +# output = [f for f in files] |
| 60 | +# output.sort() |
| 61 | +# output.insert(0, "..") |
| 62 | +# output.insert(0, ".") |
| 63 | + |
| 64 | +# if args.one: |
| 65 | +# output = [f for f in files] |
| 66 | +# output.sort() |
| 67 | +# for f in output: |
| 68 | +# print(f) |
| 69 | + |
| 70 | + |
| 71 | +# ------- |
| 72 | + |
| 73 | +# if args.a: |
| 74 | +# output = files # include hidden files |
| 75 | +# output.insert(0, "..") |
| 76 | +# output.insert(0, ".") |
| 77 | +# else: |
| 78 | +# # exclude hidden files |
| 79 | +# output = [f for f in files if not f.startswith('.')] |
| 80 | + |
| 81 | +# output.sort() # always sort after filtering |
| 82 | + |
| 83 | +# if args.one: |
| 84 | +# for f in output: |
| 85 | +# print(f) |
| 86 | +# else: |
| 87 | +# print(" ".join(output)) |
| 88 | + |
26 | 89 | def path_proceeding(path_argument): |
27 | 90 | if os.path.isfile(path_argument): |
28 | 91 | print(path_argument) |
29 | 92 | elif os.path.isdir(path_argument): |
30 | 93 | files = os.listdir(path_argument) |
31 | 94 | arguments_proceeding(files) |
32 | | -# elif not path_argument: |
33 | | -# print("no") |
| 95 | + |
| 96 | + |
34 | 97 |
|
35 | | -# if not args.path: |
36 | | -# print("no") |
37 | 98 | path_proceeding(args.path) |
38 | 99 |
|
39 | 100 |
|
|
0 commit comments