Skip to content

Instantly share code, notes, and snippets.

@don1138
Created November 7, 2023 01:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save don1138/0a23c33f5f61dd7f4848723392e30748 to your computer and use it in GitHub Desktop.
Save don1138/0a23c33f5f61dd7f4848723392e30748 to your computer and use it in GitHub Desktop.
Make Drag-and-Drop file paths readable by Python
# 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