Solved

Batch Script Tweak Mark II

Posted on 2012-03-10
13
323 Views
Last Modified: 2012-06-21
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
Comment
Question by:Delerium1978
  • 7
  • 5
13 Comments
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
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
 
LVL 68

Assisted Solution

by:Qlemo
Qlemo earned 500 total points
Comment Utility
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
 

Author Comment

by:Delerium1978
Comment Utility
@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
 
LVL 68

Expert Comment

by:Qlemo
Comment Utility
That was intentional, kind of fallback. What should happen with the films starting with numbers different from zero?
0
 

Author Comment

by:Delerium1978
Comment Utility
@Qlemo - i'd just want them all in the YZ0 directory.
0
 
LVL 68

Expert Comment

by:Qlemo
Comment Utility
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 68

Expert Comment

by:Qlemo
Comment Utility
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
 

Author Comment

by:Delerium1978
Comment Utility
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
 

Author Comment

by:Delerium1978
Comment Utility
*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
 

Author Comment

by:Delerium1978
Comment Utility
Ran it last night and for some reason all films have gone into the catch all YZ0 folder. Any ideas?
0
 
LVL 68

Accepted Solution

by:
Qlemo earned 500 total points
Comment Utility
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
 

Author Comment

by:Delerium1978
Comment Utility
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
 

Author Closing Comment

by:Delerium1978
Comment Utility
Excellent solution. Many thanks for your help.<br /><br />James
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now