Advertisement
Jexal

fa95106f-e80d-41d1-becb-5b285730eb09

Jan 21st, 2025 (edited)
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. import os
  2.  
  3. def create_subdirectories(base_directory, input_file):
  4. with open(input_file, 'r') as infile:
  5. for line in infile:
  6. # Remove newline characters from the directory name
  7. dir_path = line.strip()
  8. # Create the full path for the new subdirectory
  9. full_path = os.path.join(base_directory, dir_path)
  10. # Create the subdirectory if it doesn't already exist
  11. if not os.path.exists(full_path):
  12. os.makedirs(full_path)
  13. print(f"Created directory: {full_path}")
  14. else:
  15. print(f"Directory already exists: {full_path}")
  16.  
  17. # Ask the user for the base directory
  18. base_directory = input("Please enter the base directory: ")
  19. # Replace 'input.txt' with your input file name containing the directory names
  20. input_file = 'input.txt'
  21.  
  22. create_subdirectories(base_directory, input_file)
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement