Skip to content

Commit e1b4425

Browse files
committed
refactoring ls.py file
1 parent 3cec44a commit e1b4425

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

  • implement-shell-tools/ls

‎implement-shell-tools/ls/ls.py‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,23 @@
88

99
args = parser.parse_args()
1010

11+
12+
def get_files(path):
13+
files = sorted(os.listdir(path))
14+
15+
if args.a:
16+
return [".", ".."] + files
17+
18+
return [f for f in files if not f.startswith(".")]
19+
20+
1121
# Print all files first
1222
for path in args.paths:
1323
if not os.path.isdir(path):
1424
if args.one:
1525
print(path)
1626
else:
17-
print(path, end=" ")
27+
print(path, end=" ")
1828
print()
1929

2030
# Print directories
@@ -24,12 +34,7 @@
2434
if len(args.paths) > 1:
2535
print(f"\n{path}:")
2636

27-
files = sorted(os.listdir(path))
28-
29-
if args.a:
30-
files = [".", ".."] + files
31-
else:
32-
files = [f for f in files if not f.startswith(".")]
37+
files = get_files(path)
3338

3439
if args.one:
3540
for file in files:

0 commit comments

Comments
 (0)