Page 1 of 1

drag and drop multiple file on a bat file

Posted: 01 May 2022 05:12
by mt_mt
Hi All,

I would like to ask some tips how to do this, trying to drag and drop mulitple files on a bat file that run a program.

My bat file is like this, so far it only will open two text files i drap and drop. What if i want to open ten or more text files? tried to google but just really can't get it work.

Thank you.


C:\Windows\notepad.exe %1
C:\Windows\notepad.exe %2

pause


Regards,
mt

Re: drag and drop multiple file on a bat file

Posted: 01 May 2022 12:36
by aGerman
Something about like that:

Code: Select all

@echo off &setlocal
for %%i in (%*) do start "" notepad %%i
Note that the batch code receives the whole path for each file. At some point (depending on the length of the path) you will exceed the maximum length of a command line if you drop too many files.

Steffen

Re: drag and drop multiple file on a bat file

Posted: 01 May 2022 21:43
by mt_mt
Hi Steffen,

Thank you able to make it work.

was trying to make a program (not notepad) to run multiple files by batch.

But i realize it will open and run the program same times together.

My silly way
C:\Windows\notepad.exe %1
C:\Windows\notepad.exe %2

will make the program run first file (%1) then second file (%2).

for %%i in (%*) do start "" notepad %%i

I can open two drag and drop files same time but if there is a way to make the program run drag and drop files one by one? ( as the program i intend to run is a render program that eat memories).

Thank you for your time.

Regards,
mt

Re: drag and drop multiple file on a bat file

Posted: 01 May 2022 22:17
by mt_mt
found the behaviour i would like it to be after i remove the "start"

c:
cd xxxxxx(directory where the program)

for %%i in (%*) do xxxxx(program exe file name) %%i

Thank you very much.

Regards,
mt

Re: drag and drop multiple file on a bat file

Posted: 02 May 2022 00:04
by aGerman
My bad, sorry. I added the START command because people usually ask for asynchronous processing of several files :lol:

Steffen