Drag and drop files into batch file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Tami
Posts: 10
Joined: 31 Mar 2017 11:01

Drag and drop files into batch file

#1 Post by Tami » 31 Mar 2017 11:07

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? :/

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Drag and drop files into batch file

#2 Post by penpen » 31 Mar 2017 12:44

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

Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Re: Drag and drop files into batch file

#3 Post by Samir » 13 Apr 2017 14:23

Neat! I didn't think this was possible. 8)

Post Reply