Kema Posted August 25, 2006 Share Posted August 25, 2006 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 offset LAME=lame.exeset OPTS=--preset mediumFOR %%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 More sharing options...
LLXX Posted August 25, 2006 Share Posted August 25, 2006 (edited) ren *.wav.mp3 *.mp3Edit: rename command didn't work as I expected it to Edit2: figured it out:ren *.wav.mp3 *.ren *.wav *.mp3 Edited August 25, 2006 by LLXX Link to comment Share on other sites More sharing options...
gunsmokingman Posted August 25, 2006 Share Posted August 25, 2006 (edited) 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.vbsConst 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 Edited August 25, 2006 by gunsmokingman Link to comment Share on other sites More sharing options...
LLXX Posted August 25, 2006 Share Posted August 25, 2006 Wow, what I did with 2 rename commands you needed 8 lines of VB script... good work Link to comment Share on other sites More sharing options...
CoffeeFiend Posted August 26, 2006 Share Posted August 26, 2006 Wow, what I did with 2 rename commands you needed 8 lines of VB script... good work 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 More sharing options...
gunsmokingman Posted August 26, 2006 Share Posted August 26, 2006 Wow, what I did with 2 rename commands you needed 8 lines of VB script... good work Shows how much you know about script writing, there are only 2 lines that rename the files 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 = TRUEDim 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 + 4096I 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 More sharing options...
LLXX Posted August 26, 2006 Share Posted August 26, 2006 (edited) 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 August 26, 2006 by LLXX Link to comment Share on other sites More sharing options...
MrCobra Posted August 26, 2006 Share Posted August 26, 2006 FOR %i IN (*.WAV) do lame --preset medium "%~nI.wav" "%~nI.mp3" Link to comment Share on other sites More sharing options...
gunsmokingman Posted August 26, 2006 Share Posted August 26, 2006 LLXX, sorry if I misunderstood you.I do agrre with you but I do prefer to write VBS script over Batch files. The original poster now has acouple of valid ways of doing what he wants. He did make a request for either a batch or vbs script. Link to comment Share on other sites More sharing options...
LLXX Posted August 26, 2006 Share Posted August 26, 2006 FOR %i IN (*.WAV) do lame --preset medium "%~nI.wav" "%~nI.mp3"You win for doing it all on one line Link to comment Share on other sites More sharing options...
Kema Posted August 26, 2006 Author Share Posted August 26, 2006 Thank you all very much!Really appreciate all your work and effort in this topic!Wish you all good day! Link to comment Share on other sites More sharing options...
Kema Posted August 26, 2006 Author Share Posted August 26, 2006 Act.Run(Lame & " " & StrF.Name & " " & OPTS), 1, True will work.Saves As Run_Lame.vbsConst 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 + 4096Neither 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 scriptFOR %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 More sharing options...
LLXX Posted August 27, 2006 Share Posted August 27, 2006 (edited) I created a few files with extension '.wav.mp3' and tried my solutionren *.wav.mp3 *.ren *.wav *.mp3and it does indeed work 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 beenfor %%i in (*.wav) do lame --preset medium "%%~nI.wav" "%%~nI.mp3"For use in a batch file, since % expands a variable otherwise. Edited August 27, 2006 by LLXX Link to comment Share on other sites More sharing options...
LLXX Posted August 27, 2006 Share Posted August 27, 2006 (edited) Perhaps you forgot that the source files were still thereO RLY?FOR %%F IN (*.WAV) DO %LAME% %OPTS% "%%F"DEL *.WAVYes, 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? (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 August 27, 2006 by LLXX Link to comment Share on other sites More sharing options...
Kema Posted August 27, 2006 Author Share Posted August 27, 2006 Right after i posted my last post i got it work with help of another code posted here earlier!working solution is now@echo offset LAME=lame.exeset OPTS=--preset mediumFOR %%F IN (*.wav) DO %LAME% %OPTS% "%%F"del *.wavren *.mp3 *.ren *.wav *.mp3 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now