Link to home
Start Free TrialLog in
Avatar of Delerium1978
Delerium1978Flag for United Kingdom of Great Britain and Northern Ireland

asked on

Batch Script Tweak Mk III

Hi Guys and Gals

Following on from this thread:

https://www.experts-exchange.com/questions/27626476/Batch-Script-Tweak-Mark-II.html

Im looking to alter my batch script so that it keeps going to the start of the script if there are still files to process. The current version of the script is:

@echo off
setlocal enabledelayedexpansion

set "BaseDir=D:\Videos\DVD Transfer"
set "Pass[1]=-an"
set "Pass[2]=-acodec libmp3lame -ac 2 -ab 128kb -ar 44100"

path %BaseDir%\Encoding Software;%path%

for %%S in (Comedy Documentaries Films "Music Videos" Musicals TV) do (
  echo Processing %%~S folder
  set "Source=%BaseDir%\To Encode\%%~S"
  for %%F in ("!Source!\*.mkv") do (
    echo File: %%~nF
    set Filename=%%~nF

    set "Destination=%BaseDir%\Completed Encodes\%%~S\!Filename!"
    echo TV Documentaries | findstr "%%~S" >nul && (
      if "!Filename:~-7,1!"==" " (
        if "!Filename:~-6,1!"=="S" (
          if "!Filename:~-3,1!"=="E" (
            set "Destination=%BaseDir%\Completed Encodes\%%~S\!Filename:~0,-7!\Season !Filename:~-5,2!"
    ) ) ) )

		if "%%~S" == "Films" (
  		set "Destination=%BaseDir%\Completed Encodes\%%~S\YZ0\!Filename!"
  		for %%L in (ABC DEF GHI JKL MNO PQR STU VWX YZ0) do echo %%L | find /i "!Filename:~0,1!" >null && (
    		set "Destination=%BaseDir%\Completed Encodes\%%~S\%%L\!Filename!"
  		)
		)



    md "!Destination!" 2>nul

    for /l %%P in (1,1,2) do (
      echo Pass: %%P
      ffmpeg.exe -y -i "!Source!\%%~nF.mkv" -pass %%P -passlogfile "%BaseDir%\To Encode\%%~nF.log" -threads 8 -vcodec libxvid -vtag XVID -f avi -aspect 16:9 -r 25 -s 720x576 -b 1250kb -minrate 1250kb -maxrate 1250kb -bufsize 2048k !Pass[%%P]! "!Source!\!Filename!.avi"
    )
		del *.log
    
		move "!Source!\%%~nF.avi" "!Destination!\%%~nF.avi" >nul
    
    del "%BaseDir%\To Encode\%%~S\%%~nF.mkv" >nul
    
    start "" "D:\Program Files\FlashFXP\FlashFXP.exe" -tray -c2 -go FATNAS.fqf
    echo.
  )
)

Open in new window


It now processes the file, then moves it to the right place and deletes the original source file. Once thats done, it ftp's it to my nas. The issue i've got is that im constantly adding files to the TV, Films etc folders whilst this batch script is running so its only picking up the files it found when it originally set off and not the new ones. Is it possible for it to loop back around until it finds nothing to process?

James
Avatar of Paul Tomasi
Paul Tomasi
Flag of United Kingdom of Great Britain and Northern Ireland image

Blimey! I remember that code...
Avatar of Steven Carnahan
@paultomasi  

So do I   :)

It sounds like the goal now is to make it a continous loop.  It seems that we have spent our whole lives trying to prevent continous loops, also know as runaway programs years ago.  Funny how times change.
Avatar of Delerium1978

ASKER

Well i've made it half way through my girlfriends collection but its taking so long so anything i can do to automate it the better :)

So yeah, continuous loop until there are no files found to process. It possible?
ASKER CERTIFIED SOLUTION
Avatar of Paul Tomasi
Paul Tomasi
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
EDIT:  paul - you beat me to it.   :)

ORIGINAL:


Okay, I had to review the code to remember what was going on.

Here is what is happening:

1. Look in %basedir%\toencode\comedy and process all files
2. Look in %basedir%\toencode\documentaries and process all files
.
.
.
x. Look in %basedir%\toencode\tv and process all files
x+1. Exit

You want it to loop back to 1. after completing x instead of moving to x+1.

The simple answer is to put a dreaded "goto" logic in the program and just let it run continously period.  This would not be the cleanest method but would be the shortest.

Put a label between these two lines:

    path %BaseDir%\Encoding Software;%path%

    for %%S in (Comedy Documentaries Films "Music Videos" Musicals TV) do (

Something like :_CLOOP_

Then at the very end of the code (after the last ")" put the following:

goto _CLOOP_


This will put it into a continous loop that you will have to break out of when you are ready.

There are more options in various degrees of complexity as well.
Here is another option - actually just adding to what paul and I already gave you by giving you an option to restart or not after each full loop through the program as long as your system will support the "choice" command (the last 4 lines of the code)

@echo off
setlocal enabledelayedexpansion

set "BaseDir=D:\Videos\DVD Transfer"
set "Pass[1]=-an"
set "Pass[2]=-acodec libmp3lame -ac 2 -ab 128kb -ar 44100"

path %BaseDir%\Encoding Software;%path%

:CLOOP
for %%S in (Comedy Documentaries Films "Music Videos" Musicals TV) do (
  echo Processing %%~S folder
  set "Source=%BaseDir%\To Encode\%%~S"
  for %%F in ("!Source!\*.mkv") do (
    echo File: %%~nF
    set Filename=%%~nF

    set "Destination=%BaseDir%\Completed Encodes\%%~S\!Filename!"
    echo TV Documentaries | findstr "%%~S" >nul && (
      if "!Filename:~-7,1!"==" " (
        if "!Filename:~-6,1!"=="S" (
          if "!Filename:~-3,1!"=="E" (
            set "Destination=%BaseDir%\Completed Encodes\%%~S\!Filename:~0,-7!\Season !Filename:~-5,2!"
    ) ) ) )

            if "%%~S" == "Films" (
              set "Destination=%BaseDir%\Completed Encodes\%%~S\YZ0\!Filename!"
              for %%L in (ABC DEF GHI JKL MNO PQR STU VWX YZ0) do echo %%L | find /i "!Filename:~0,1!" >null && (
                set "Destination=%BaseDir%\Completed Encodes\%%~S\%%L\!Filename!"
              )
            )



    md "!Destination!" 2>nul

    for /l %%P in (1,1,2) do (
      echo Pass: %%P
      ffmpeg.exe -y -i "!Source!\%%~nF.mkv" -pass %%P -passlogfile "%BaseDir%\To Encode\%%~nF.log" -threads 8 -vcodec libxvid -vtag XVID -f avi -aspect 16:9 -r 25 -s 720x576 -b 1250kb -minrate 1250kb -maxrate 1250kb -bufsize 2048k !Pass[%%P]! "!Source!\!Filename!.avi"
    )
            del *.log
   
            move "!Source!\%%~nF.avi" "!Destination!\%%~nF.avi" >nul
   
    del "%BaseDir%\To Encode\%%~S\%%~nF.mkv" >nul
   
    start "" "D:\Program Files\FlashFXP\FlashFXP.exe" -tray -c2 -go FATNAS.fqf
    echo.
  )
set choice=
set /p choice="Do you wish to restart? Press 'y' and enter for Yes: "
if not '%choice%'=='' set choice=%choice:~0,1%
if '%choice%'=='y' goto CLOOP
)
No. CTRL-C is not the way to go. He did say loop while there are still files to process.
Your right.  I missed part of your code.  That would make it a continous loop ONLY until nothing was found and would not require any input like I did in my last code.  Very nice.  

I don't like the CTRL-C option anyway however it is the simpilist solution as I originally stated in my first reply with code.
Thanks both for your input. Paul won this round i think as he got the nail on the head 1st with loop until no more files to process.

Thanks again

James
WOW! That was luky!

Thank you.
grats and good job Paul.  :)

Yes James, Paul's code is the best choice.  His will do the job without ANY interaction from the user. Both of my options require the user to do something.