[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 372
  • Last Modified:

Batch Script Tweak Mark II

Following on from the awesome work paultomasi did on this question thread:

http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/Q_27623491.html

It's become apparent that the dvd -> digital conversion has filled up the folder making it very hard to find films you're looking for therefore I've added another folder level to split the films into sections of the alphabet. Unfortunatley, because i've done this, the batch script previously made isn't quite fit for purpose for the films section anymore. How can I amend the attached script to allow for the new folders?

Films ->

ABC
DEF
GHI
JKL
MNO
PQR
STU
VWX
YZ0

@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!"
    ) ) ) )
    
    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%\!Filename!.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]! "!Destination!\!Filename!.avi"
    )

    move "%BaseDir%\To Encode\%%~S\%%~nF.mkv" "%BaseDir%\To Encode\Old MKV\%%~nF.mkv"
    echo.
  )
)

cd %BaseDir%
del *.log

Open in new window


James
0
Delerium1978
Asked:
Delerium1978
  • 7
  • 5
2 Solutions
 
Bill PrewCommented:
So, do you only want to do this for the Films subfolder, no others?

Also, will this addition level only exist in the destination folder structure, but in the source files as well?

And will it be the first letter of the file name that determine what subfolder to look in?

~bp
0
 
QlemoDeveloperCommented:
I suppose this is what you are after. Insert it into line 18 or 24:
if "%%~S" == "Films" (
  set Destination=
  for %%L in (ABC DEF GHI JKL MNO PQR STU VWX YZ0) do echo %%L | find /i "!Filename:~1,0!" >null && (
    set "Destination=%BaseDir%\Completed Encodes\%%~S\%%L\!Filename!"
  )
  if not defined Destination set "Destination=%BaseDir%\Completed Encodes\%%~S\YZ0\!Filename!"
)

Open in new window

0
 
Delerium1978Author Commented:
@billprew

"So, do you only want to do this for the Films subfolder, no others?"

Currenly just films.

"Also, will this addition level only exist in the destination folder structure, but in the source files as well?"

Just destination. Source will remain the same.

"And will it be the first letter of the file name that determine what subfolder to look in?"

Yes first letter of file name will determine it.

@Qlemo - nice addition. Only problem with that is that the folder "YZ0" will house all films that start with a number, not just 0. Any way around that?
0
Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

 
QlemoDeveloperCommented:
That was intentional, kind of fallback. What should happen with the films starting with numbers different from zero?
0
 
Delerium1978Author Commented:
@Qlemo - i'd just want them all in the YZ0 directory.
0
 
QlemoDeveloperCommented:
If you just want to have folders 123 456 789, add those to the FOR. You can remove my line 6 then, or change it e.g. to the Films folder.
Note: I have edited a typo in above code, not changing the logic.
0
 
QlemoDeveloperCommented:
Sorry, cross-post.
@Qlemo - nice addition. Only problem with that is that the folder "YZ0" will house all films that start with a number, not just 0. Any way around that?

 i'd just want them all in the YZ0 directory.
That is exactly what the original code snippet is doing - all films starting with a digit will go into YZ0 folder.
0
 
Delerium1978Author Commented:
Missed the code snippet "if not defined Destination set "Destination=%BaseDir%\Completed Encodes\%%~S\YZ0\!Filename!"".

Question though, Destination is initially defined at line 17. Would this not conflict with this statement?
0
 
Delerium1978Author Commented:
*sigh* i need to get some sleep. You already have this covered with "set Destination=".

I'll try this out overnight and let you know the outcome. Many thanks :)

James
0
 
Delerium1978Author Commented:
Ran it last night and for some reason all films have gone into the catch all YZ0 folder. Any ideas?
0
 
QlemoDeveloperCommented:
Oops. Major failure on my side. I've also simplified the "fallback" slightly.
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!"
  )
)

Open in new window

0
 
Delerium1978Author Commented:
Ahhhh so the fallback was being called even if it found the folder. Will try this new snippet tonight and report back :) Many thanks.

James
0
 
Delerium1978Author Commented:
Excellent solution. Many thanks for your help.<br /><br />James
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now