Solved

Batch Script Tweak Mark II

Posted on 2012-03-10
13
353 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
13 Comments
 
LVL 54

Expert Comment

by:Bill Prew
ID: 37705776
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 70

Assisted Solution

by:Qlemo
Qlemo earned 500 total points
ID: 37705788
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
ID: 37705815
@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
Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

 
LVL 70

Expert Comment

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

Author Comment

by:Delerium1978
ID: 37705834
@Qlemo - i'd just want them all in the YZ0 directory.
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 37705837
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
 
LVL 70

Expert Comment

by:Qlemo
ID: 37705847
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
ID: 37705862
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
ID: 37705869
*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
ID: 37706582
Ran it last night and for some reason all films have gone into the catch all YZ0 folder. Any ideas?
0
 
LVL 70

Accepted Solution

by:
Qlemo earned 500 total points
ID: 37706614
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
ID: 37707502
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
ID: 37711243
Excellent solution. Many thanks for your help.<br /><br />James
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How do I delete 2 45
Wrap Oraccle SQL*Plus executable Command 4 104
LINUX Field Separators 7 79
Bash script to include windows servers 13 41
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…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

752 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