Batch Script Improvement

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
mydxbtester
Posts: 7
Joined: 23 Feb 2015 07:12

Batch Script Improvement

#1 Post by mydxbtester » 23 Feb 2015 07:26

Daily, we generate around 1500+ to 2000+ call recordings and it's a very tedious to have those files converted to mp3 and stored to it's corresponding dated folder. The batch script below does the job but is there a way to refine/improve it? I mean it shouldn't copy (lame'd) and should skip all those files already existing in the !targetfolder! so as to preserve CPU resources.

Code: Select all

@echo off
setlocal enabledelayedexpansion
set FolderIncoming=C:\Original\PhoneCalls\AllCalls
set FileMask=201*.wav
set FolderSorted=C:\Backup\CompDrive - MyCompany\CallRecordings
Set LameLocation=C:\Program Files (x86)\Lame

for %%a in ("%FolderIncoming%\%FileMask%") do (
   set FileName=%%~na
   echo Processing '!FileName!' ...
   set TargetYear=!FileName:~0,4!
   set TargetFolder=!TargetYear!\!FileName:~0,10!
   if not exist "%FolderSorted%\!TargetFolder!" md "%FolderSorted%\!TargetFolder!"
   "%LameLocation%\lame.exe" -m j --cbr -b 320 -q 0 --lowpass 22.05 "%%a" "%FolderSorted%\!TargetFolder!\%%~na.mp3"
)


Thank you.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Batch Script Improvement

#2 Post by Squashman » 23 Feb 2015 07:32

Use another IF NOT EXIST.

mydxbtester
Posts: 7
Joined: 23 Feb 2015 07:12

Re: Batch Script Improvement

#3 Post by mydxbtester » 23 Feb 2015 07:36

If it's not too much to ask, can you show me how to do that as I'm not sure as to where to put that conditional statement.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch Script Improvement

#4 Post by foxidrive » 23 Feb 2015 07:54

Test this on some unimportant files:

Code: Select all

@echo off
setlocal enabledelayedexpansion
set FolderIncoming=C:\Original\PhoneCalls\AllCalls
set FileMask=201*.wav
set FolderSorted=C:\Backup\CompDrive - MyCompany\CallRecordings
Set LameLocation=C:\Program Files (x86)\Lame

for %%a in ("%FolderIncoming%\%FileMask%") do (
   set FileName=%%~na
   set TargetYear=!FileName:~0,4!
   set TargetFolder=!TargetYear!\!FileName:~0,10!
            if not exist "%FolderSorted%\!TargetFolder!\%%~na.mp3" (
               echo Processing '!FileName!' ...
               if not exist "%FolderSorted%\!TargetFolder!" md "%FolderSorted%\!TargetFolder!"
               "%LameLocation%\lame.exe" -m j --cbr -b 320 -q 0 --lowpass 22.05 "%%a" "%FolderSorted%\!TargetFolder!\%%~na.mp3"
            )
)

mydxbtester
Posts: 7
Joined: 23 Feb 2015 07:12

Re: Batch Script Improvement

#5 Post by mydxbtester » 23 Feb 2015 23:14

Perfect!!! Thank you.

Post Reply