Guest User

Untitled

a guest
Jun 24th, 2024
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | Software | 0 0
  1. import py7zr #downloaded this with Pip to play with 7zip files
  2. import os #this allows me to use the .path stuff
  3.  
  4. #Define the paths
  5. downloads_folder = os.path.expanduser('~/Downloads') #the ~ signifies my home directory
  6. extraction_folder = os.path.expanduser('~/Romtest')
  7.  
  8. for file_name in os.listdir(downloads_folder):
  9. if file_name.endswith('.7z'):
  10. file_path = os.path.join(downloads_folder, file_name)
  11. try:
  12. with py7zr.SevenZipFile(file_path, mode='r') as archive:
  13. archive.extractall(path=extraction_folder)
  14. print(f"Extracted: {file_name} into {extraction_folder}")
  15. except Exception as e:
  16. print(f"Failed to extract {file_name}")
  17.  
  18. print("All files processed")
Advertisement
Add Comment
Please, Sign In to add comment