Skip to content

Commit 3ba1f93

Browse files
feat: add files for day-10
1 parent cbe8862 commit 3ba1f93

File tree

5 files changed

+38
-1
lines changed

5 files changed

+38
-1
lines changed

Day-10/01-convert-string-to-list.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
folder_paths = input("Enter a list of folder paths separated by spaces: ").split()

Day-10/02-main-construct.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
def main():
2+
folder_paths = input("Enter a list of folder paths separated by spaces: ").split()
3+
print(folder_paths)
4+
5+
# Print elements in the list
6+
#for folder_path in folder_paths:
7+
# print(folder_path)
8+
9+
if __name__ == "__main__":
10+
main()

Day-10/03-list-files-in-folders.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import os
2+
3+
def list_files_in_folder(folder_path):
4+
try:
5+
files = os.listdir(folder_path)
6+
return files, None
7+
except FileNotFoundError:
8+
return None, "Folder not found"
9+
except PermissionError:
10+
return None, "Permission denied"
11+
12+
def main():
13+
folder_paths = input("Enter a list of folder paths separated by spaces: ").split()
14+
15+
for folder_path in folder_paths:
16+
files, error_message = list_files_in_folder(folder_path)
17+
if files:
18+
print(f"Files in {folder_path}:")
19+
for file in files:
20+
print(file)
21+
else:
22+
print(f"Error in {folder_path}: {error_message}")
23+
24+
if __name__ == "__main__":
25+
main()

Day-10/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Lists Part-2

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
- List comprehensions.
6161
- Nested lists and advanced list operations.
6262
- Practice exercises and examples:
63-
- Example: Parsing a complex configuration file with nested lists.
63+
- Example: Print list of files in the list of folders provided
6464

6565
## Day 11: Working with Dictionaries and Sets
6666
- Dictionaries and key-value pairs.

0 commit comments

Comments
 (0)