Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def get_target_directory():
- """
- Prompt the user to enter a valid directory path.
- Keeps prompting until a valid directory path is entered.
- If the specified path does not exist, prompt the user to create it.
- """
- while True:
- target_directory_path = input(Fore.CYAN + "> Enter the target directory's path: ").strip().strip('"')
- if not target_directory_path:
- print(Fore.RED + "> Please enter a valid directory path.\n")
- elif not os.path.isdir(target_directory_path):
- create_dir = input(Fore.YELLOW + f"> The specified path does not exist. Do you want to create it? (y/n): ").strip().lower()
- if create_dir == 'y':
- try:
- os.makedirs(target_directory_path)
- print(Fore.GREEN + f"> Directory created: {target_directory_path}\n")
- return target_directory_path
- except Exception as e:
- print(Fore.RED + f"> Failed to create directory: {target_directory_path}. Error: {str(e)}\n")
- else:
- print(Fore.RED + "> Please enter a valid directory path.\n")
- else:
- return target_directory_path
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement