Created
November 7, 2023 01:02
-
-
Save don1138/0a23c33f5f61dd7f4848723392e30748 to your computer and use it in GitHub Desktop.
Make Drag-and-Drop file paths readable by Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Read File Path v1.0 | |
# Dreg-and-Dropping into terminal a file with spaces in its name (User/Folder/File\ Name.txt) can cause errors. | |
# This script makes sure file paths are readable by Python | |
import shlex | |
# Ask the user for a file path | |
file_path_input = input("Enter the path to the target file: ").strip() | |
file_path_components = shlex.split(file_path_input) | |
# Reconstruct the file path by joining the components | |
file_path = ' '.join(file_path_components) | |
# Display the file path provided by the user | |
print(f"You entered the file path: {file_path}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment