Jump to content

Can Someone Help Modify This Batch File?


ElastomerGuy

Recommended Posts

nchto was kind enough to post the following batch file which almost does what I need. The batch file below goes through the subdirectory c:\user\mp3 and recursively calls switch to convert the .mp3 files in c:\user\mp3 to new mp3 files in c:\user\mp3 128. My directories are of the form

in=h:\music\artist name\cd name

out=h:\mp3\artist name\cd name

I've changed the in and out directories in the batch file to correspond to my directories. Unfortunately, I'm losing the cd name subdirectory when the conversion is completed. So, for example, let's say I have a subdirectory h:\music\bruce springsteen\born to run and that that subdirectory has 10 songs in it. Suppose further that I have a subdirectory h:\music\bruce springsteen\greatest hits which has 20 songs in it. When I run the batch file, it is converting the songs in both subdirectories but they all wind up in a subdirectory called h:\mp3\bruce springsteen. The output directory has 30 songs in it, the songs in both the h:\music\bruce springsteen\born to run and h:\music\bruce springsteen\greatest hits subdirectories. Is there any way to change the batch file so that the complete directory structure is preserved so in my example I'd wind up with h:\mp3\bruce springsteen\born to run with 10 songs in it and h:\mp3\bruce springsteen\greatest hits with 20 songs in it?

Thanks in advance for any help that can be offered.

 

@ECHO OFF

SET in=C:\User\MP3\

SET out=C:\User\MP3 128\

FOR /D %%G IN (*) DO ECHO Converting files in: %in%%%G & ECHO Saving them to: %out%%%G & ECHO. & "C:\Program Files\NCH Swift Sound\Switch\switch.exe" -addfolder "%in%%%G" -format .mp3 -settings .mp3 CBR 128 TRUE JOINT FALSE -outfolder "%out%%%G" -overwrite PROMPT -convert -hide -exit

ECHO All done!

PAUSE

Link to comment
Share on other sites

ElastomerGuy, change the batch file slightly so it looks like:

 

@ECHO OFF

SET in=h:\music\

SET out=h:\mp3\

cd %in%

FOR /D %%G IN (*) DO "C:\Program Files\NCH Swift Sound\Switch\switch.exe" -addfolder "%in%%%G" -format .mp3 -settings .mp3 CBR 128 TRUE JOINT FALSE -outfolder "%out%%%G" -overwrite PROMPT -convert -hide -exit

 

It doesn't do all the fancy "this is the input folder" "this is the output folder", but that's why it wasn't working as expected (and why it wouldn't work if you weren't in the topmost music folder).

 

This batch file should work in most Windows-type DOS prompts, including CMD.EXE, 4DOS/4NT/Take Command, and probably Windows Powershell.

 

I haven't figured out all the different command line options for Switch (I've never used it before, so I'm learning fast!). So at the moment, the script prompts for each new folder, and it's not smart enough NOT to try and convert non-audio files (which is a bit of a problem if you store album artwork or lyrics in the same folder, but that's not NCH's fault!)

 

Let me know if there are any problems.

 

 

Cheers,

PC Pete

(P.S. I'm in the same boat as you - I've got about 7,000+ PCM files in 780+ folders that I need to convert to FLAC, and Switch is the first program I've found that comes close to what I'm after! Good luck!)

Link to comment
Share on other sites

I believe the developers will be looking at including the "[same as source file]" option back into the program, which should remove the need to use a batch file.

Link to comment
Share on other sites

I believe the developers will be looking at including the "[same as source file]" option back into the program, which should remove the need to use a batch file.

That would be really great, especially since my "fix" doesn't actually work as expected on standard DOS/CMD prompts. :unsure: D'oh.

 

I apologise for setting up an incorrect answer...

 

This is a major limitation of the command prompt, and I'm trying to find a good workaround... I can get it to work fine in 4NT, and with some tricks, in Windows XP's command shell, but doing the same thing in all standard command prompts is really hard without programming to help!

 

Stay tuned.

Link to comment
Share on other sites

ElastomerGuy, please try the following batch file and see how you go with it.

 

There are a couple of things you need to be aware of before trying this batch file.

 

First, it will ONLY run in a command shell in Windows XP (Home, Professional, or x64 edition). If you're running Windows 98 or earlier, this won't work. I'm not sure about windows 2000, or NT, or Me.

 

Second, it depends on two things:

1) there are no tildes (~) in any of your folder names, and

2) Your music folder structure is always <whatever music root folder>\Artist\Album\files.mp3

 

It's not really important whether the directory structure is artist\album or album\artist, just as long as there are only two "layers" of directories.

 

This is a REALLY difficult thing for windows (well, CMD anyway) to do, so the batch file is neither elegant nor fast, but it should work on your system.

 

Be aware, once you start this sucker, you're going to have a hell of a time trying to get it to stop- unless you have a quick ctrl-C trigger finger!

 

I've tested this on two systems and it seemed to work, but occasionally Switch stops responding and the batch file starts running real fast. In that case, you need to stop the script, exit the DOS prompt, kill any Switch processes still running, and open a new DOS prompt and try it again. Note that if this does happen, you will end up starting over from scratch. You can avoid this by changing the overwrite command to -overwrite PROMPT (instead of -overwrite ALWAYS).

 

You should probably cut and paste this, as the quotes and back quotes are critical, unless you know what you're doing.

 

This also depends on the output directory structure already existing, as per the other thread you posted.

 

Good luck, and let me know if this works!

 

-PC Pete

 

 

@ECHO OFF

set in=h:\music\

set out=h:\mp3\

cd /d "%in%"

for /f "usebackq delims=~" %%i in (`dir . /ad /b`) do for /f "usebackq delims=~" %%j in (`dir "%%i" /ad /b`) do "C:\Program Files\NCH Swift Sound\Switch\switch.exe" -addfolder "%in%%%i\%%j" -format .mp3 -settings .mp3 CBR 128 TRUE JOINT FALSE -outfolder "%out%%%i\%%j" -overwrite ALWAYS -convert -hide -exit

Link to comment
Share on other sites

Thank you Pc Pete

 

My folder structure is G:\Music\Album

 

So I altered the batch file to the following:-

 

@ECHO OFF

set in=G:\Music\

set out=G:\MP3\

cd /d "%in%"

for /f "usebackq delims=~" %%i in (`dir . /ad /b`) do "C:\Program Files\NCH Swift Sound\Switch\switch.exe" -addfolder "%in%%%i" -format .mp3 -settings .mp3 CBR 128 TRUE JOINT FALSE -outfolder "%out%%%i" -overwrite ALWAYS -convert -hide -exit

 

I copied the whole of the folders in G:\Music\ into G:\MP3\

 

and it almost worked on the 6 folders I tested. 320bps VBR, 192bps CBR in G:\Music\ all converted to 128bps CBR in G:\MP3\

 

However when converting from FLAC to MP3 128bps it does not overwrite but adds another file into the folder. This is the way that Switch works; unless there is another options I cannot find.

 

What I next did was to search in G:\MP3\ for *.mp3 and *.flac and deleted all found. This was more complicated than it sounds because I could not see a way to search only in a specific folder in XP i.e G:\MP3\. So I copied the whole lot to an emptied drive; searched/deleted there and then moved the empty folders back. Then ran the batch file again

 

Only 400+ folders to go. Good job I have a spare XP machine to do this job on!

 

I guess that if you want Stereo rather than Joint Stereo just change TRUE JOINT FALSE to TRUE STEREO FALSE??

Link to comment
Share on other sites

ElastomerGuy, change the batch file slightly so it looks like:

 

 

 

It doesn't do all the fancy "this is the input folder" "this is the output folder", but that's why it wasn't working as expected (and why it wouldn't work if you weren't in the topmost music folder).

 

This batch file should work in most Windows-type DOS prompts, including CMD.EXE, 4DOS/4NT/Take Command, and probably Windows Powershell.

 

I haven't figured out all the different command line options for Switch (I've never used it before, so I'm learning fast!). So at the moment, the script prompts for each new folder, and it's not smart enough NOT to try and convert non-audio files (which is a bit of a problem if you store album artwork or lyrics in the same folder, but that's not NCH's fault!)

 

Let me know if there are any problems.

 

 

Cheers,

PC Pete

(P.S. I'm in the same boat as you - I've got about 7,000+ PCM files in 780+ folders that I need to convert to FLAC, and Switch is the first program I've found that comes close to what I'm after! Good luck!)

========================================

I can name another :-)

 

 

Musikone

Link to comment
Share on other sites

Thank you Pc Pete

You're completely welcome. Glad I could help.

However when converting from FLAC to MP3 128bps it does not overwrite but adds another file into the folder. This is the way that Switch works; unless there is another options I cannot find.

Yeah, it looks like the developers have done that by design - it would be so easy for a tiny slip to delete the source files even if the conversion didn't happen the way you wanted. I think of it as a command-line airbag. ;)

What I next did was to search in G:\MP3\ for *.mp3 and *.flac and deleted all found. This was more complicated than it sounds because I could not see a way to search only in a specific folder in XP i.e G:\MP3\. So I copied the whole lot to an emptied drive; searched/deleted there and then moved the empty folders back. Then ran the batch file again

Not sure what you mean by searching in XP... but I agree it's primitive. I use a tool called 4NT from JPSoft. It's a DOS/CMD replacement, and it's just the most powerful and flexible tool around, if you have to work with command lines. You can search for files with different extensions or date ranges and delete them if the other file exists, all that kind of stuff. It's US$49 (I think), and if you do any command-line work, you'll be in heaven. I've been using it since, er, 1996, so I know it inside and out. Only problem - when you don't have access to it, DOS looks like a sad, empty, useless tool. Which it is, of course! (I'm not affiliated with JPSoft, I just love their stuff).

 

And if you want the same thing for explorer, try Directory Opus. It's just incredible. Like explorer on steroids. And you CAN use that to find and batch rename and archive and just about anything you want in one go. And you can create collections and favourites, and it handles audio and video previews, all that stuff.

 

I guess that if you want Stereo rather than Joint Stereo just change TRUE JOINT FALSE to TRUE STEREO FALSE??

I'm not a big user of MP3 stuff, so I'm not sure about the stereo alternatives. I know that some players are really inefficient when fed with one type of stereo encoding vs the other, but I'm not sure which ones, nor why. Try both, see which ones ring your bell!

Link to comment
Share on other sites

I can name another :-)

I'm listening! I've tried a lot of batch converters, but they all fall in a heap with high-res PCM (192k/24 or even 96/24) files, and not one of the ones I've tried (including FLAC) that work on XP x64, can handle unicode names, RIFF tags, BWF, BEXT, or CART chunk data. So I'm always interested.

Link to comment
Share on other sites

Not sure what you mean by searching in XP...

 

I have several folders on my G: drive (G: being my 750GB USB backup drive) that hold MP3/Flac files. For this exercise it is the only drive I now have that had the space to store another 40GB folder. Searching for MP3 would have bought up every instance not just those in the one folder, G:\MP3\, that I wanted to delete. I would have to be very careful what I selected in the seach dialogue before pressing the delete buton.

 

I can see that the software you are recommending would have done the job. But it is unlikely that I will be doing very much of this kind of searching in future so the expense will not be worthwhile. I will use my work around if necessary.

 

Work around: move all the data on a drive that is bigger than the required space i.e 40GB+ my F: in this case, copy the MP3 folder over to F: do the searches, delete, move the now fileless folder back to G: and move back from G: the data for F:

Link to comment
Share on other sites

Work around: move all the data on a drive that is bigger than the required space i.e 40GB+ my F: in this case, copy the MP3 folder over to F: do the searches, delete, move the now fileless folder back to G: and move back from G: the data for F:

I know what you mean... I've got a 2Tb RAID drive (video editing) and a 1.2Tb RAID drive (audio editing and music library), and between them there's less than 400G free. I gotta do some housecleaning sometime... :huh:

When I used to be a computer guru, we had a saying : Data expands to fill all available space. We were only half-kidding, but it's absolutely true. Gone are the days when we'd say "Who the hell needs six hundred and forty K RAM? What a waste!" B)

Link to comment
Share on other sites

"Who the hell needs six hundred and forty K RAM? What a waste!" B)

 

 

I remember that well. I quickly upgraded my RAM from 16k to 64k on my TRS80, to get a 5 1/4" floppy drive, but baulked when a 640K Amstrad came out. I got the cheaper 512K. My first hard drive was 20Mb and I struggled to fill it! I do not throw away old hard disk but keep them for backup. But now I have number of 60/80GB drive just sitting around; too small. I need my 750GB drive.

Link to comment
Share on other sites

  • 4 weeks later...

that script didn't work for me. here's what I did.

 

1. ran dir f:\wmamusic /ad /b /s>wmalist.txt - to list all folders under my wma music folder.

 

2. manually removed the top level folders from wmalist.txt, which were the first lines, e.g.; the first 2 lines in the example below

F:\wmamusic\artist1

F:\wmamusic\artist2

F:\wmamusic\artist1\CD1

F:\wmamusic\artist1\CD2

F:\wmamusic\artist2\CD1

...

 

3. replaced "&" with "and" in wmalist.txt because "&" would cause the batch script to stop reading the line at that point. e.g.; Kate & Anna McGarrigle -> Kate and Anna McGarrigle

 

4. ran this batch file:

 

@echo off

 

for /f "tokens=*" %%i in (f:\wmalist.txt) do (set in=%%i) & (call :next)

 

goto :EOF

 

:next

set line=%in:~12%

set out=f:\mp3cnvrt\%line%

 

MD "%OUT%"

 

"C:\Program Files\NCH Swift Sound\Switch\switch.exe" -format .mp3 -settings .mp3 CBR 192 TRUE STEREO FALSE -addfolder "%in%" -outfolder "%out%" -overwrite ALWAYS -convert -SHOW -EXIT

 

======

script notes:

 

set line=%in:~12%

set out=f:\mp3cnvrt\%line%

 

these 2 lines change F:\wmamusic\artist1\CD1 to f:\wmacnvrt\artist1\CD1, etc.

 

I had to add MD "%OUT%" to keep switch from asking me if I wanted to create each new folder.

 

hope this helps someone else.

Link to comment
Share on other sites

  • 2 weeks later...
3. replaced "&" with "and" in wmalist.txt because "&" would cause the batch script to stop reading the line at that point. e.g.; Kate & Anna McGarrigle -> Kate and Anna McGarrigle

Yeah, I forgot about the other command separator characters in filenames, only because I now always rename them when I'm ripping/copying. That's from bitter experience. That and UNICODE filenames.

 

Same holds true for +,^`' and " too.

 

The script also needs to be executed from in the root of the music folders, i.e. with all the artist folders (or album folders if you use album\artist paths), but it should have worked on almost any two-level tree structure. Maybe I missed another compatibility problem...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...