Drag and Drop Folders to Create Array & Execute Commands

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
davep
Posts: 24
Joined: 29 May 2008 14:03
Location: Nauf Kakalak

Drag and Drop Folders to Create Array & Execute Commands

#1 Post by davep » 13 Apr 2009 15:43

I hope I can explain this well. The more I think about it, the more confused I get.

I've written a simple batch file that lets a user drag and drop a folder onto it, it gleans a few key filenames from the folder's contents, and then plants those filenames as arguments for a proprietary CLI executable that merges closed-captioning data with a WMV file, based on Windows Media File Editor. This works well for a processing a single folder now and then, but it has come to my attention that we need to re-process hundreds of old folders with updates captions. Rather than drag and drop, wait and hour for it to finish, drag and drop again, wait an hour for it to finish, etc., I'd like to drag and drop a large group of folders at once, therefore I've come here for some expert advice. A few tidbits before I paste in the code: The folders are named by project number, and contain only numbers. Within each folder is a captioning text file, a master source MPEG file, and a multi-bitrate WinMedia file. The output file generated is simply folderName.wmv.

So, if I still have your attention, how can I expand this to let me process multiple folders, one after another?

Code: Select all

rem drag a folder onto this file to start script
@echo off

set encoder="C:\Program Files\ScriptEncoder\scriptencoder.exe"

for %%A in (%1\*.txt) do set script_file=%%A

for %%B in (%1\*.mpg) do set source_file=%%B

for %%C in (%1\*mbr.wmv) do set target=%%C

set output_file=%source_file:~0,-4%.wmv

set profile="C:\Program Files\ScriptEncoder\normal.prx"

title %output_file%

rem echo the values to make sure they're correct
echo.
echo.SCRIPT FILE = %script_file%
echo.
echo.SOURCE FILE = %source_file%
echo.
echo.     TARGET = %target%
echo.
echo.OUTPUT FILE = %output_file%
echo.
echo.    PROFILE = %profile%
echo.

rem start the encoder now
%encoder% ^
%script_file% ^
%source_file% ^
%target% ^
%output_file% ^
%profile%

echo.
echo.
pause
exit


avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

#2 Post by avery_larry » 15 Apr 2009 09:22

You'll have to work on this a bit (untested) but perhaps a front-end program like this:

Assuming your code is called "dosmerge.cmd", then you could create script file called "multimerge.cmd" like this:

Code: Select all

@echo off
for %%a in (%*) do (
   echo Processing %%a . . .
   start "merge" /b /wait cmd /s /c "dosmerge %%a"
)


Drop your multiple folders onto this script and it'll call the other script one directory at a time.

If you have any directory names with spaces then you'll have to do some work with the "" in your script.

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

#3 Post by avery_larry » 15 Apr 2009 09:25

Perhaps better than what I said before -- all in the same file like this:


Code: Select all

rem drag one or more folder(s) onto this file to start script 
@echo off

for %%a in (%*) do (
   echo Processing %%a . . .
   call :process %%a
)
echo All finished
pause
exit
goto :eof

:process
set encoder="C:\Program Files\ScriptEncoder\scriptencoder.exe"

for %%A in (%1\*.txt) do set script_file=%%A

for %%B in (%1\*.mpg) do set source_file=%%B

for %%C in (%1\*mbr.wmv) do set target=%%C

set output_file=%source_file:~0,-4%.wmv

set profile="C:\Program Files\ScriptEncoder\normal.prx"

title %output_file%

rem echo the values to make sure they're correct
echo.
echo.SCRIPT FILE = %script_file%
echo.
echo.SOURCE FILE = %source_file%
echo.
echo.     TARGET = %target%
echo.
echo.OUTPUT FILE = %output_file%
echo.
echo.    PROFILE = %profile%
echo.

rem start the encoder now
%encoder% ^
%script_file% ^
%source_file% ^
%target% ^
%output_file% ^
%profile%

echo.
echo.

davep
Posts: 24
Joined: 29 May 2008 14:03
Location: Nauf Kakalak

#4 Post by davep » 15 Apr 2009 11:06

for %%a in (%*) do (
echo Processing %%a . . .
call :process %%a
)
echo All finished
pause
exit
goto :eof


I should have known it would be that simple! I was unaware that (%*) was a possibility. It all makes perfect sense now. I updated my batch with your changes and it worked flawlessly. It's two days to crunch time, and I'm worry-free! Thank you very much for such a simple and elegant solution.

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

#5 Post by avery_larry » 15 Apr 2009 14:30

Aww shucks. I try.


:lol:

Post Reply