DoctaSax Posted December 3, 2012 Posted December 3, 2012 Basically, I'm trying to make a .bat file that players can use to rename a bunch of mp3s that they place in a folder to file names that my esp will recognize. I don't know anything about non-beth scripting (sad, sad), so I expanded on a .bat file that comes with the new vegas radio extender and wound up with this: @Echo OffpausesetLocal EnableDelayedExpansionset extension=mp3set index=1for %%f IN (*.%extension%) do ( set /A index+=1 set index=!index! ren "%%f" "SOFOLong!index!.%extension%")@echo [Done!]pause:end [/Code] which replaces the names with "SOFOLong" + number. So far so good.2 problems though:* The first 9 will display as SOFOLong1/2/3/etc.mp3 but what I'd really want is SOFOLong01/02/03/etc.mp3. Anybody know how to do this, or if it can be done at all? (If not, that's ok, it's just a format preference. I can still redirect the file paths in my esp.) * if any of the source files' names starts with a number, the renaming process seems to skip a count and start with SOFOLong2.mp3 instead of SOFOLong1.mp3. I'd like to avoid this, make it foolproof. Any insight appreciated, even if it's saying "you're SOL".
gregathit Posted December 3, 2012 Posted December 3, 2012 Well, I really can't help too much other than to post a couple of bat files that were written by the Japanese guys who made lovers with PK. They changed formats for one of the PK versions and issued these bat files for folks to convert their sounds to the new format layout. It is for oblivion so it might or might not help. I pulled the previous version and included another that changes all the gibberish to a machine translation - should be easier to understand now.
DoctaSax Posted December 3, 2012 Author Posted December 3, 2012 Thanks greg, but I don't get it. Been browsing some sites on batch files, too, but y'know... *woosh* -- (Odd that the DL counter doesn't show I dl'd that, btw.)
Slammer64 Posted December 3, 2012 Posted December 3, 2012 DoctaSax, I could create a bash script under Linux to do that easy enough, but since we need Windows for for most games, you might try a variation of the following. The command executes a for loop, initializing the counter i with the first argument (0), steps the counter with the second argument (1) and stops when the counter exceeds argument number 3 (9). The % sign in front of i shows it is a variable. This works only for 0 to 9, you will need to adjust slightly, if you go from 10 to 99, etc. that is each time an extra digit changes in the zero padding: for /l %i in (0, 1, 9) do rename test-tmp-0000%i.* test-tmp-%i.*
DoctaSax Posted December 4, 2012 Author Posted December 4, 2012 Thanks Slammer. I do fear I need it spelled out a bit more - hate to pull the whole damsel-in-distress act, but I don't know the syntax, the functions or anything. The only bit in that code that was mine was adding the prefix to the output the initial "set index=1" should be 0 (mistyped), but the problem with the count starting with 2 instead of 1 persists when there is any number in any of the file names already. That's the main thing that bugs me: mp3s tend to have numbers. (The leading zeroes for numbers under 10 is more something I'd like to have so I don't need to reset file paths for 72 audio entries - doable, but mindnumbingly repetitive.) Recap: let's say there can be anywhere between 15 and 40 randomly named mp3s in a given folder (8 folders), then how I get a neat rename going that replaces the names with a given prefix (SOFOLong, SOFOLove etc) and a correct count starting at 1 or 01? Like going from left to right here:
Slammer64 Posted December 4, 2012 Posted December 4, 2012 If that's the case DoctaSax you might try it this way: @echo off REM Meant to be run in a directory that you choose. But DO NOT run this in the Windows directory! REM Prefix to add to the filename set strPrefix=Green - REM Set this to be the files that you want to prefix with the "strPrefix" above "*.*" means all the files REM set fname=*.* set fname=tst.bat REM List the files to be renamed for %%f in (%fname%) DO echo Rename file "%%f" to "%strPrefix%%%f" REM Rename the files REM for %%f in (%fname%) DO ren "%%f" "%strPrefix%%%f"
DoctaSax Posted December 4, 2012 Author Posted December 4, 2012 Ah, well, in the mean time I shamelessly adapted something from elsewhere & it seems to stop the misnumbering: @Echo OffSETLOCAL ENABLEDELAYEDEXPANSIONSET Count=1FOR /F "tokens=*" %%A IN ('DIR /OD /B *.mp3') DO ( REN "%%~A" SOFOLong!Count!.###REN *.### *.mp3 SET /A Count = !Count! + 1)ENDLOCAL [/Code] Doesn't seem to play nice with whatever I try to do to add leading zeroes, but at least the count is right. And it'll probably be faster for me to change the filepaths for the 'under-ten' files than spending more time on getting those leading zeroes right. That was just a convenience/preference thing, and I need to get back to work on story & effects. Thanks anyhow
Slammer64 Posted December 4, 2012 Posted December 4, 2012 Sorry I couldn't help more DoctaSax, I'm more of a Linux/Bash/Perl man myself.
DoctaSax Posted December 4, 2012 Author Posted December 4, 2012 Sorry I couldn't help more DoctaSax' date=' I'm more of a Linux/Bash/Perl man myself. [/quote'] No worries
astymma Posted December 4, 2012 Posted December 4, 2012 Why don't you write it using Windows Script Host? Be a lot simpler and more powerful. Can even use the SDK's Digital Certificate tool to create a signed certificate to avoid issues with users who have WSH set to only run trusted certificate scripts using WSH. It's optional for Win95/NT and guaranteed to be on all other versions of Windows since Win98 up to Win7.
DoctaSax Posted December 4, 2012 Author Posted December 4, 2012 Why don't you write it using Windows Script Host? Be a lot simpler and more powerful. Can even use the SDK's Digital Certificate tool to create a signed certificate to avoid issues with users who have WSH set to only run trusted certificate scripts using WSH. It's optional for Win95/NT and guaranteed to be on all other versions of Windows since Win98 up to Win7. Well, what I have right now is functioning now that I've corrected a few filepaths - took less time than I feared - so I'll leave it at that. Just needed to have something in place so that users wouldn't have to manually rename their tunes and wind up not doing it.
astymma Posted December 4, 2012 Posted December 4, 2012 Why don't you write it using Windows Script Host? Be a lot simpler and more powerful. Can even use the SDK's Digital Certificate tool to create a signed certificate to avoid issues with users who have WSH set to only run trusted certificate scripts using WSH. It's optional for Win95/NT and guaranteed to be on all other versions of Windows since Win98 up to Win7. Well' date=' what I have right now is functioning now that I've corrected a few filepaths - took less time than I feared - so I'll leave it at that. Just needed to have something in place so that users wouldn't have to manually rename their tunes and wind up not doing it. [/quote'] Yeah, it was more for future reference... figured you'd already solved your issue.
sanguisfrigidus Posted December 26, 2012 Posted December 26, 2012 i've often referenced http://www.robvanderwoude.com for bats... and http://www.robvanderwoude.com/battech_leadingzero.php seems to be the relevant part.. just for reference again...
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