File tree Expand file tree Collapse file tree 5 files changed +38
-1
lines changed Expand file tree Collapse file tree 5 files changed +38
-1
lines changed Original file line number Diff line number Diff line change
1
+ folder_paths = input ("Enter a list of folder paths separated by spaces: " ).split ()
Original file line number Diff line number Diff line change
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 ()
Original file line number Diff line number Diff line change
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 ()
Original file line number Diff line number Diff line change
1
+ # Lists Part-2
Original file line number Diff line number Diff line change 60
60
- List comprehensions.
61
61
- Nested lists and advanced list operations.
62
62
- 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
64
64
65
65
## Day 11: Working with Dictionaries and Sets
66
66
- Dictionaries and key-value pairs.
You can’t perform that action at this time.
0 commit comments