Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using drag and drop from another directory onto a batch file does not work

I have a folder structure that looks like this:

project
    bin
        my_program.exe
        misc_stuff.exe
    DROP_OVER_ME.bat
    input_file.txt

Basically, I want to be able to drag and drop the input file on top of the DROP_OVER_ME.bat batch file and have it pass on the path of the input file to the exe.

This is what my batch file looks like:

@echo off
start bin/my_program.exe %1
exit

When I drag and drop input_file.txt over the batch file, everything works fine -- my_program.exe successfully receives the path of the input file and runs.

However, when input_file.txt is located outside the project folder, dragging and dropping it makes the batch file throw up a popup message saying

Windows cannot find 'bin/my_program.exe'. Make sure you typed the name correctly, and then try again.

How can I fix my batch file so I can drag and drop files from any arbitrary location inside my filesystem?

like image 571
Michael0x2a Avatar asked Mar 07 '13 00:03

Michael0x2a


1 Answers

Sounds like the batch script is basing the current working directory as the directory you're dragging from, and not the directory containing the script. (You can test this by adding an echo %cd% && pause to your script if you wish.) Try modifying your script as follows to remove any ambiguity about file paths:

@echo off
cd /d "%~dp0"
start "" "bin\my_program.exe" "%~f1"
exit /b
like image 167
rojo Avatar answered Oct 16 '22 21:10

rojo