Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run command with drag and drop onto batch file

Tags:

batch-file

cmd

I want to drag and drop a file onto a batch file in order to run the below command on it. How do I go about running the command on the dropped file?

PotreeConverter.exe <dropped file> -o C:/output -p index
like image 500
Mark Avatar asked Aug 15 '18 23:08

Mark


People also ask

What is %% in a batch file?

Use double percent signs ( %% ) to carry out the for command within a batch file. Variables are case sensitive, and they must be represented with an alphabetical value such as %a, %b, or %c. ( <set> ) Required. Specifies one or more files, directories, or text strings, or a range of values on which to run the command.

Can a batch file prompt for input?

You are able to prompt a user for input using a Batch script function.


2 Answers

The path of the file, when you drop it on the BATfile, will be returned as a normal %1 argument.

so :

@echo off
PotreeConverter.exe "%~1" -o C:/output -p index

You can use %* if you drop more then 1 file

Example :

@echo off

for %%a in (%*) do echo [%%a] was dropped on me 
pause
like image 108
SachaDee Avatar answered Oct 17 '22 06:10

SachaDee


Following this easy guide.

Create a batch file test.bat with the contents

@echo off
echo The full path of the file is: %1
pause

Drag any file onto it, you will see that %1 is replaced with the full path for that file in quotes.

Now you know how to execute some command that takes a path to a file as an argument:

@echo off
some_command_that_takes_a_path_to_a_file %1
like image 27
OrangeSherbet Avatar answered Oct 17 '22 06:10

OrangeSherbet