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
Delerium1978Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewIT / Software Engineering ConsultantCommented:
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
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
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
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
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
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
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
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
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
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft DOS

From novice to tech pro — start learning today.