|
Answer» Looking for a way to trim first 5 character places off of a bunch of file names named 01 - filename.mp3 so that the file is trimmed to a name of filename.mp3 without the 01(space)-(space) before the song title.
I saw a program for sale called better file rename for $20, but was WONDERING if anyone knew of a way to do it for free through batch using a read in file name and then trim and rename as filename without the first 5 characters leading into the file name? I dont see why batch wouldnt be able to do it, but this exceeds my batching abilities, so a solution would be a learning experience if you could also describe what does what in the batch.
I have about 3000 SONGS that I want to trim this off of, so I am not sure if there is a way to read in with wildcard *.mp3 for all files in that directory and have it CHUG through them until they are all renamed without first 5 characters that always start with 01(space)-(space), 02(space)-(space) ect where the leading 2 digits is the track number so maybe ??(space)-(space) can be used as a wildcard type match for the files to test against them, or if the test would be to look for a dash ( - ) at the 4th character place of each file name and if there is a dash at the 4th character place, then trim first 5 character places off of the filename with a read in of that files name, trim, and rename?
Thanks.Try this. It's not fully tested so instead of renaming the files it will copy them to your %temp% folder from which they can be deleted at will. When you have tested and proved the script, change the copy line to ren "!filename!" "!newfilename!"
Code: [Select]echo off cls setlocal enabledelayedexpansion
:: Set default directory to the directory containing .mp3 files pushd path\to\files\|| echo PUSHD FAILED - job terminated&exit /b
:: Loop thru' a bare directory listing of mp3 files, reading each filename :: into the environment variable %filename%, creating a new environment :: variable %newfilename% containing %filename% less the first 5 chars :: then renaming..
for /f "tokens=*" %%1 in ('dir /b *.mp3') do ( set filename=%%1 set newfilename=!filename:~5! copy "!filename!" "%temp%\!newfilename!" )
popd
Quote from: DaveLembke on August 22, 2010, 11:45:34 AM Looking for a way to trim first 5 character places off of a bunch of file names named 01 - filename.mp3 so that the file is trimmed to a name of filename.mp3 without the 01(space)-(space) before the song title.
I saw a program for sale called better file rename for $20, but was wondering if anyone knew of a way to do it for free through batch using a read in file name and then trim and rename as filename without the first 5 characters leading into the file name? I dont see why batch wouldnt be able to do it, but this exceeds my batching abilities, so a solution would be a learning experience if you could also describe what does what in the batch.
I have about 3000 songs that I want to trim this off of, so I am not sure if there is a way to read in with wildcard *.mp3 for all files in that directory and have it chug through them until they are all renamed without first 5 characters that always start with 01(space)-(space), 02(space)-(space) ect where the leading 2 digits is the track number so maybe ??(space)-(space) can be used as a wildcard type match for the files to test against them, or if the test would be to look for a dash ( - ) at the 4th character place of each file name and if there is a dash at the 4th character place, then trim first 5 character places off of the filename with a read in of that files name, trim, and rename?
Thanks.
what you need is a string manipulation tool that is free and versatile to use. you can download sed for windows and then do this
Code: [Select]C:\test>dir /b /a-d *mp3 01 - song1.mp3 02 - song2.mp3
C:\test>dir /b /a-d *mp3|sed "s/^.[0-9]*[ \t]*-[ \t]*//" song1.mp3 song2.mp3
Use a for loop to iterate and rename your files. Note it takes care of variable number of spaces between your numbers, not just 5. COOL! ... I am going to use this right now to trim up the file names. Thanks!!!For renaming versatility, I cannot recommend a program more than ExplorerXP -- it can trim, stuff, replace and renumber multiple files.
The version I have does not work on vista but is fine on XP (its not been updated on download.com since 2006, so I doubt there will be a new version)
Graham
Quote from: gpl on August 23, 2010, 12:33:03 AMFor renaming versatility, I cannot recommend a program more than ExplorerXP -- it can trim, stuff, replace and renumber multiple files.
there are alot of such kind of software for renaming files. One can create such a UTILITY with just simple scripting.
Quote from: DaveLembke on August 22, 2010, 11:45:34 AMLooking for a way to trim first 5 character places off of a bunch of file names.
This solution is nearly the same as TCs in reply 1. TCs is better. Except We show the output.
Reference:
http://www.dostips.com/DtTipsStringManipulation.php
C:test>Display trim5.bat
echo off echo. > newmp3.txt dir /b *.mp3 > mp3.txt type mp3.txt echo.
setlocal enabledelayedexpansion for /f delims= %%i in (mp3.txt) do ( set mp=%%i echo mp=!mp! set mp=!mp:~5! echo mp=!mp! echo !mp! >> newmp3.txt copy %%i !mp! rem ren %%i !mp! rem del %%i ) echo Display Trim5 type newmp3.txt rem ( will need double quotes for source and destination for the copy command. )
Output:
C:test>trim5.bat Kalimba.mp3 Maid with the Flaxen Hair.mp3 SleepAway.mp3
mp=Kalimba.mp3 mp=ba.mp3 1 file(s) copied. mp=Maid with the Flaxen Hair.mp3 mp=with the Flaxen Hair.mp3 1 file(s) copied. mp=SleepAway.mp3 mp=Away.mp3 1 file(s) copied. Display Trim5 ba.mp3 with the Flaxen Hair.mp3 Away.mp3 C:test>
|