(SOLVED) Help creating a batch file
Moderator: DosItHelp
(SOLVED) Help creating a batch file
Hi, I am trying to write a batch file that will take all file names in a directory that match *.ext and put them in a command line. The command line is:
program.exe file1.ext + file2.ext + file3.ext + ...
I have been trying a few different things with for loops, but I can't figure this out. Thanks for any help.
program.exe file1.ext + file2.ext + file3.ext + ...
I have been trying a few different things with for loops, but I can't figure this out. Thanks for any help.
Last edited by icon123 on 11 Oct 2012 22:00, edited 6 times in total.
Re: Help creating a batch file...
Code: Select all
@echo off & cls
For /F "tokens=*" %%A in ('Dir /B /A:-D "*.txt"') Do (
< nul set /p "=%%A + ">>temp.txt
)
For /F "tokens=*" %%B in ('type "temp.txt"') Do set line=%%B
echo Program.exe %line%
Del "temp.txt" >nul
pause
but there is an extra + sign at the end i couldn't get it removed
Last edited by abc0502 on 13 Sep 2012 10:32, edited 2 times in total.
Re: Help creating a batch file...
Try this:
Code: Select all
@echo off
for %%a in (*.ext) do call set var=%%var%% + "%%a"
set "var=%var:~2%"
echo %var%
program.exe %var%
pause
Re: Help creating a batch file...
abc0502 wrote:Code: Select all
Del /F /S /Q "temp.txt" >nul
Be very careful where you use /S and the del command.
It's not needed to delete a file that is going to exist, so just use
Code: Select all
Del "temp.txt"
Re: Help creating a batch file...
foxidrive wrote:Try this:Code: Select all
@echo off
for %%a in (*.ext) do call set var=%%var%% + "%%a"
set "var=%var:~2%"
echo %var%
program.exe %var%
pause
that is nice

and thanks for the note i will modify it
Re: Help creating a batch file...
Thank you both!
Looking at foxidrive's example, it appears that whe the %var% is added to the command line, it is missing the first " around the 1st value. i.e. the command line becomes:
program.exe file1.ext"+"file2.ext"+"file3.ext" ...
Edit: I added a " to the command line:
and now it works great. Thanks again.
Looking at foxidrive's example, it appears that whe the %var% is added to the command line, it is missing the first " around the 1st value. i.e. the command line becomes:
program.exe file1.ext"+"file2.ext"+"file3.ext" ...
Edit: I added a " to the command line:
Code: Select all
program.exe "%var%
and now it works great. Thanks again.
Re: Help creating a batch file...
There must be another reason, as here it returns this:
Perhaps you edited the code...
Code: Select all
"find.txt" + "printerlist.txt" + "printers.txt" + "replace.txt" + "replace2.txt"
Perhaps you edited the code...
Re: Help creating a batch file...
Foxidrive code work fine with me, and there is no missing quotes, but there is 2 spaces between the program.exe and the first quote at the first file
Re: Help creating a batch file...
I had to take the spaces out between the " and the +, maybe that did it. Regardless, its working great. Thank you so much, I spent a lot of time on that one.
Now for a tweak...
Is there anyway I can modify it to only use the files that I drag and drop onto the .bat file? Currently, if I drag and drop a few of the files in the directory, it will still process all the files with *.ext that are in the directory. Thanks again.
Now for a tweak...
Is there anyway I can modify it to only use the files that I drag and drop onto the .bat file? Currently, if I drag and drop a few of the files in the directory, it will still process all the files with *.ext that are in the directory. Thanks again.
Re: Help creating a batch file - How can I make it drag and
This has to use full paths as the batch file could be anywhere.
Code: Select all
@echo off
:loop
set var=%var%+"%~1"
shift
if not "%~1"=="" goto :loop
set "var=%var:~1%"
echo "c:\my folder\program.exe" %var%
pause
Re: Help creating a batch file - How can I make it drag and
Works great, thanks. What would I have to add to the script to move the files that I drag and dropped to another directory? For example if the files that I drag and drop from is in directory \dir1, I want to move the processed files to \dir1\dir2. Thanks again.
Re: Help creating a batch file - How can I make it drag and
It depends on your program.exe as often you can specify an output path.
Re: Help creating a batch file - How can I make it drag and
I want to move the source files.
Re: Help creating a batch file - How can I make it drag and
Try this:
Code: Select all
@echo off
md "%~dp1\dir2" 2>nul
set num=0
:loop
set /a num=num+1
set var=%var%+"%~1"
set file~%num%="%~1"
shift
if not "%~1"=="" goto :loop
set "var=%var:~1%"
echo "c:\my folder\program.exe" %var%
for /f "tokens=1,* delims==" %%a in ('set file~') do (
move /y "%%~b" "%%~dpb\dir2" >nul
set %%a=
)
pause
Re: Help creating a batch file - How can I make it drag and
Awesome, thanks so much! I have one more request. Can you tell me how I would modify the below script for drag and drop and moving the source files as well. Similar to what you just did with the other script. Thanks.
Code: Select all
@SET mkvmerge_PATH=C:\mkvtoolnix\mkvmerge.exe
@SET eac3to_PATH=C:\eac3to\eac3to.exe
for /f "delims=;" %%a in ('dir *.mts /b') do (
%eac3to_PATH% "%%a" "%%~na.h264" "%%~na.ac3" "%%~na.sup"
%MKVMERGE_PATH% -o "%%~na.mkv" --forced-track 0:no --compression 0:none -d 0 -A -S -T --no-global-tags --no-chapters "%%~na.h264" --forced-track 0:no --compression 0:none -a 0 -D -S -T --no-global-tags --no-chapters "%%~na.ac3" --forced-track 0:no -s 0 -D -A -T --no-global-tags --no-chapters "%%~na.sup" --track-order 0:0,1:0,2:0
)