Jump to content

run lame and give it right parameters for all files in a dir!


Recommended Posts

I got small problem, that's i got bat file for running lame in a dir for all .wav files i have and convert them to .mp3 but problem is that bat file add old extension to new file with new extension, i give example:

song.wav will be rung though lame and end up with name song.wav.mp3 , i don't want .wav extension on new file just song.mp3, i'm not sure it's possible in bat file to do that so maybe vbs file can, here is bat file:

--CODE--

@echo off

set LAME=lame.exe

set OPTS=--preset medium

FOR %%F IN (*.WAV) DO %LAME% %OPTS% "%%F"

DEL *.WAV

--CODE--

this is how command should be "lame.exe --preset medium song.wav song.mp3" but bat file gives "lame.exe --preset medium song.wav song.wav.mp3", it dosen't remove the old extension before giving it to lame as parameter so i have to rename them all manually, sure there are renaming programs but i just want it in script easy and fast, nothing fancy!

so can anyone help me with new script that does this simple task? i don't know any bat or vbs programming and not intressed in it either just want it to work :)

hopefully there is one or more who like a simple challenge like this!

Thank you!

Link to comment
Share on other sites


Here is a VBS script that will Rename all the Whatever.wav.mp3 to Whatever.mp3 I have tested the Rename part and that worked. How ever I do not have Lame.exe so I do not know if this line Act.Run(Lame & " " & StrF.Name & " " & OPTS), 1, True will work.

Saves As Run_Lame.vbs

Const OverwriteExisting = TRUE
Dim Fso : Set Fso = CreateObject("Scripting.FileSystemObject")
Dim Act : Set Act = CreateObject("Wscript.Shell")
Dim CD : CD = Act.CurrentDirectory
'/->If Full Path Is Needed Change To -> Lame = "HardDrive:\Folder\lame.exe"
Dim Lame : Lame = "lame.exe" '<- Change This If Full Path Is Needed
Dim OPTS : OPTS = "--preset medium"
Dim DelFile, Rename, StrF
'/-> Binds To The Current Directory
Dim Folder : Set Folder = Fso.GetFolder(CD)
Dim File : Set File = Folder.Files
'/-> For Each Loop
For Each StrF In File
If InStr(StrF.Name, ".wav") Then '/-> Filter Only Accepts Files With .Wav In The Name
Act.Run(Lame & " " & StrF.Name & " " & OPTS), 1, True
Rename = Replace(StrF.Name,".wav","")
DelFile = StrF.Name
Fso.CopyFile(StrF.Name), (Rename),OverwriteExisting
Fso.DeleteFile(DelFile)
End If
Next
Act.Popup "Completed Conversion And Rename", 5, "Finished", 0 + 32 + 4096

BeforeScript.PNG

AfterScript.PNG

Edited by gunsmokingman
Link to comment
Share on other sites

Wow, what I did with 2 rename commands you needed 8 lines of VB script... good work :whistle:

Actually, how many LOCs doesn't really matter that much. If I had made a little app to do this job, it would have been FAR longer (code quality e.g. error handling, documentation, use a XML config file (for lame settings and the like), checking command line args, app's architecture, expandability/readability concerns, whatever). I don't see how that would have made it a "lesser" solution (or perhaps I could try to fit the whole thing on one line?) And his script actually runs lame too instead of just renaming files (more features in a few more lines. No big deal really.) Between a batchfile and vbscript to do the same job (both being kind of old ways to do things and not overly great languages nor very powerful or anything), I'm not really sure of which one I'd pick...

But if you want to nit-pick, then there's lots... Language choice (and arguably shell too - wscript instead of cscript), hardcoded stuff, coding standards (variable naming, indentation, comments, etc), maintainability/readability and such things. And even one possible "bug" for files already having ".wav" in their name - like the ones generated by his previous batch (".wav.mp3" and such), will be fed to lame again (He's not checking the extension or using a RegEx but just doing a in-string check).

Either ways, no need for that app IMHO. BeSweet does the batch conversions just fine ;)

Link to comment
Share on other sites

Wow, what I did with 2 rename commands you needed 8 lines of VB script... good work :whistle:

Shows how much you know about script writing, there are only 2 lines that rename the files :hello:

1:\ Rename = Replace(StrF.Name,".wav","")

2:\ Fso.CopyFile(StrF.Name), (Rename),OverwriteExisting

The best part is there is no cmd window that appears as the script is running.

I did not want to post a script like this it 14 lines long including the message box.

Const OverwriteExisting = TRUE
Dim Fso : Set Fso = CreateObject("Scripting.FileSystemObject")
Dim Act : Set Act = CreateObject("Wscript.Shell")
Dim CD, Lame, OPTS : CD = Act.CurrentDirectory : Lame = "lame.exe" : OPTS = "--preset medium"
Dim DelFile, File, Folder, Rename, StrF
Set Folder = Fso.GetFolder(CD) : Set File = Folder.Files
For Each StrF In File
If InStr(StrF.Name, ".wav") Then
Act.Run(Lame & " " & StrF.Name & " " & OPTS), 1, True
Rename = Replace(StrF.Name,".wav","") : DelFile = StrF.Name
Fso.CopyFile(StrF.Name), (Rename),OverwriteExisting : Fso.DeleteFile(DelFile)
End If
Next
Act.Popup "Completed Conversion And Rename", 5, "Finished", 0 + 32 + 4096

I do program in VB.net but for a simple function like this I prefer VBS script, to batch scripting.

Link to comment
Share on other sites

What I meant was, just appending the two rename commands to the batch file already listed in the OP is the simplest solution.

VBscript has its uses, but for a simple automation like this, a batch file is all that's necessary.

Edited by LLXX
Link to comment
Share on other sites

Act.Run(Lame & " " & StrF.Name & " " & OPTS), 1, True will work.

Saves As Run_Lame.vbs

Const OverwriteExisting = TRUE
Dim Fso : Set Fso = CreateObject("Scripting.FileSystemObject")
Dim Act : Set Act = CreateObject("Wscript.Shell")
Dim CD : CD = Act.CurrentDirectory
'/->If Full Path Is Needed Change To -> Lame = "HardDrive:\Folder\lame.exe"
Dim Lame : Lame = "lame.exe" '<- Change This If Full Path Is Needed
Dim OPTS : OPTS = "--preset medium"
Dim DelFile, Rename, StrF
'/-> Binds To The Current Directory
Dim Folder : Set Folder = Fso.GetFolder(CD)
Dim File : Set File = Folder.Files
'/-> For Each Loop
For Each StrF In File
If InStr(StrF.Name, ".wav") Then '/-> Filter Only Accepts Files With .Wav In The Name
Act.Run(Lame & " " & StrF.Name & " " & OPTS), 1, True
Rename = Replace(StrF.Name,".wav","")
DelFile = StrF.Name
Fso.CopyFile(StrF.Name), (Rename),OverwriteExisting
Fso.DeleteFile(DelFile)
End If
Next
Act.Popup "Completed Conversion And Rename", 5, "Finished", 0 + 32 + 4096

Neither renaming part or lame part works on my system, when lame is running it opens dos window, since dos program and that happpens is that a dos windows is opened then close right away and all files get correct name still but without extension!

and bat script

FOR %i IN (*.WAV) do lame --preset medium "%~nI.wav" "%~nI.mp3"

dosen't work either :( , all i get is a error saying:

"Following use of path operator instead of command parameter is invalid: "%~nI.mp3""

rougly translated from swedish, you can get lame from hxxp://www.free-codecs.com/download/Lame_Encoder.htm , it's free and legal, try it yourself, i'm using win XP Pro swedish edition, don't think that should have anything todo with errors but who knows, not me for sure!

Link to comment
Share on other sites

I created a few files with extension '.wav.mp3' and tried my solution

ren *.wav.mp3 *.
ren *.wav *.mp3

and it does indeed work :thumbup

Basically, the first rename strips off the .mp3 on the end so you're left with a bunch of .wav files, then the second command changes the .wav to .mp3 and it's done.

The one-line solution should've been

for %%i in (*.wav) do lame --preset medium "%%~nI.wav" "%%~nI.mp3"

For use in a batch file, since % expands a variable otherwise.

Edited by LLXX
Link to comment
Share on other sites

Perhaps you forgot that the source files were still there
O RLY?
FOR %%F IN (*.WAV) DO %LAME% %OPTS% "%%F"

DEL *.WAV

Yes, one could have deleted the source files too, but we wouldn't want to assume he wants to get rid of them, or force him to that so he can have files named properly...
Then what's that line doing in the batch file the OP posted? :lol::lol: (s)he obviously doesn't want the *.wav's to be around afterwards.

Basically the OP just wants to rename *.wav.mp3 to *.mp3

Edited by LLXX
Link to comment
Share on other sites

Right after i posted my last post i got it work with help of another code posted here earlier!

working solution is now

@echo off

set LAME=lame.exe
set OPTS=--preset medium

FOR %%F IN (*.wav) DO %LAME% %OPTS% "%%F"
del *.wav
ren *.mp3 *.
ren *.wav *.mp3

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...