Skip to content

Instantly share code, notes, and snippets.

@etherealxx
Last active January 30, 2023 22:01
Show Gist options
  • Save etherealxx/aac4fe027100bb2fa90a0a6c771b1f6b to your computer and use it in GitHub Desktop.
Save etherealxx/aac4fe027100bb2fa90a0a6c771b1f6b to your computer and use it in GitHub Desktop.

About

Drag and drop file or folder into the .bat file, and it will convert the path of said folder/file into a python variable, which can be used later.

Rename the .bat file to the same name as your python file in order for it to work (no need to tweak the inside of the .bat file). And make sure both the .bat file and the .py file are in the same directory.

Tested work on Windows 11.

@echo off
set curdir=%~dp0
set file_path="%~1"
set file_path=%file_path:"=%
set file_path=%file_path:\=\\%
set file_path=%file_path: =^ %
set file_name=%~n0
python "%curdir%%file_name%.py" "%file_path%"
pause
import os, sys
file_path = sys.argv[1]
print(file_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment