Page 1 of 1

Drag and drop files into batch file

Posted: 31 Mar 2017 11:07
by Tami
Hello,

i wanted to ask how i can drop files into an Batch File. So i drop two files and the first file has the variable %variable1% and the second %variable2% . How do i do that? I saw that this is pssobile, so can anyone post a code for me? :/

Re: Drag and drop files into batch file

Posted: 31 Mar 2017 12:44
by penpen
You can access "drag and dropped" files using the command line accessors (%0, ... %9, %* - if using more than 9 arguments you may use the "shift" command):

Code: Select all

@echo off
setlocal enableExtensions disableDelayedExpansion

echo Command line: %0 %*
echo Command line argument 1: "%~1"
echo Command line argument 2: "%~2"
pause

endlocal
goto :eof

Result (drag and drop two files named "no_space.txt" and "with space.txt":

Code: Select all

Command line: "Z:\test.bat" Z:\no_space.txt "Z:\with space.txt"
Command line argument 1: "Z:\no_space.txt"
Command line argument 2: "Z:\with space.txt"
Drücken Sie eine beliebige Taste . . .
(If you wnat to execute these files, then you could call them using "call "%~1"", or "call "%~2"" without the outer doublequotes.)

penpen

Re: Drag and drop files into batch file

Posted: 13 Apr 2017 14:23
by Samir
Neat! I didn't think this was possible. 8)