Home > database >  Trying to Drag-n-Drop more than 9 files into batch script
Trying to Drag-n-Drop more than 9 files into batch script

Time:11-17

The code below is a simple example of what I'm trying to do. Basically, I want to be able to drag and drop more than 9 files into this script and have it iterate through each file one by one instead and run them through the "Run_Conversion_1064.bat" script.

The SHIFT method doesn't seem to be applicable to what I'm trying to accomplish.

ECHO Running BATCH....
cd /d %~dp0

CALL Run_Conversion_1064.bat %1 
CALL Run_Conversion_1064.bat %2 
CALL Run_Conversion_1064.bat %3
CALL Run_Conversion_1064.bat %4 
CALL Run_Conversion_1064.bat %5 
CALL Run_Conversion_1064.bat %6
CALL Run_Conversion_1064.bat %7
CALL Run_Conversion_1064.bat %8
CALL Run_Conversion_1064.bat %9

pause

goto end

CodePudding user response:

This works for me:

@echo off

:again


call "C:\temp\20211117\Run_Conversion_1064.bat" %1
shift

if "%1"=="" goto :done
goto :again


:done
pause

Note I've used the full path to Run_Conversion_1064.bat because it's not on my path.

Run_Conversion_1064.bat gets the full path to each file, e.g. "C:\temp\poc2449.patch"

Did what I expected dropping 14 files onto this batch file.

CodePudding user response:

Using shift or %* are the only ways to deal with > 9 arguments as far as I know.

@echo off
if "%~1"=="" goto help

:loop
echo Do something with %~1
shift
if not "%~1"=="" goto loop
goto :EOF

:help
echo.Run me with some parameters...

rem For this example, provide dummy arguments and run self
call %0 foo "hello world" 1 2 3 4 5 6 7 8 9 bar
  • Related