

InterviewSolution
Saved Bookmarks
1. |
Solve : trim first 5 characters off of file names? |
Answer» <html><body><p>Looking for a way to trim first 5 character places off of a bunch of file names named<br/>01 - filename.mp3 so that the file is trimmed to a name of filename.mp3 without the 01(space)-(space) before the song title.<br/><br/>I saw a program for sale called better file rename for $20, but was <a href="https://interviewquestions.tuteehub.com/tag/wondering-7723068" style="font-weight:bold;" target="_blank" title="Click to know more about WONDERING">WONDERING</a> 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.<br/><br/>I have about 3000 <a href="https://interviewquestions.tuteehub.com/tag/songs-239631" style="font-weight:bold;" target="_blank" title="Click to know more about SONGS">SONGS</a> 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 <a href="https://interviewquestions.tuteehub.com/tag/chug-2027578" style="font-weight:bold;" target="_blank" title="Click to know more about CHUG">CHUG</a> 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?<br/><br/>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 <br/><strong>ren "!filename!" "!newfilename!"</strong><br/><br/> Code: <a>[Select]</a>echo off<br/>cls<br/>setlocal enabledelayedexpansion <br/><br/>:: Set default directory to the directory containing .mp3 files<br/>pushd path\to\files\|| echo PUSHD <a href="https://interviewquestions.tuteehub.com/tag/failed-2080748" style="font-weight:bold;" target="_blank" title="Click to know more about FAILED">FAILED</a> - job terminated&exit /b<br/><br/>:: Loop thru' a bare directory listing of mp3 files, reading each filename<br/>:: into the environment variable %filename%, creating a new environment<br/>:: variable %newfilename% containing %filename% less the first 5 chars<br/>:: then renaming..<br/><br/>for /f "tokens=*" %%1 in ('dir /b *.mp3') do (<br/> set filename=%%1<br/> set newfilename=!filename:~5!<br/> copy "!filename!" "%temp%\!newfilename!"<br/> )<br/><br/>popd<br/><br/> Quote from: DaveLembke on August 22, 2010, 11:45:34 AM</p><blockquote>Looking for a way to trim first 5 character places off of a bunch of file names named<br/>01 - filename.mp3 so that the file is trimmed to a name of filename.mp3 without the 01(space)-(space) before the song title.<br/><br/>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.<br/><br/>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?<br/><br/>Thanks.<br/></blockquote> <br/>what you need is a string manipulation tool that is free and versatile to use. <br/>you can download <a href="http://gnuwin32.sourceforge.net/packages/sed.htm">sed for windows</a> and then do this<br/><br/> Code: <a>[Select]</a>C:\test>dir /b /a-d *mp3<br/>01 - song1.mp3<br/>02 - song2.mp3<br/><br/>C:\test>dir /b /a-d *mp3|sed "s/^.[0-9]*[ \t]*-[ \t]*//"<br/>song1.mp3<br/>song2.mp3<br/><br/>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.<br/><br/>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)<br/><br/>Graham Quote from: gpl on August 23, 2010, 12:33:03 AM<blockquote>For renaming versatility, I cannot recommend a program more than ExplorerXP -- it can trim, stuff, replace and renumber multiple files.<br/></blockquote> there are alot of such kind of software for renaming files. One can create such a <a href="https://interviewquestions.tuteehub.com/tag/utility-772057" style="font-weight:bold;" target="_blank" title="Click to know more about UTILITY">UTILITY</a> with just simple scripting. Quote from: DaveLembke on August 22, 2010, 11:45:34 AM<blockquote>Looking for a way to trim first 5 character places off of a bunch of file names. <br/></blockquote> <br/>This solution is nearly the same as TCs in reply 1. TCs is better. Except We show the output.<br/><br/>Reference: <br/><br/><a href="http://www.dostips.com/DtTipsStringManipulation.php">http://www.dostips.com/DtTipsStringManipulation.php</a><br/><br/>C:test>Display trim5.bat<br/><br/>echo off<br/>echo. > newmp3.txt<br/>dir /b *.mp3 > mp3.txt<br/>type mp3.txt<br/>echo.<br/><br/>setlocal enabledelayedexpansion<br/>for /f delims= %%i in (mp3.txt) do (<br/>set mp=%%i<br/>echo mp=!mp!<br/>set mp=!mp:~5!<br/>echo mp=!mp!<br/>echo !mp! >> newmp3.txt<br/>copy %%i !mp!<br/>rem ren %%i !mp!<br/>rem del %%i<br/>)<br/>echo Display Trim5<br/>type newmp3.txt<br/>rem ( will need double quotes for source and destination for the copy command. )<br/><br/>Output:<br/><br/>C:test>trim5.bat<br/>Kalimba.mp3<br/>Maid with the Flaxen Hair.mp3<br/>SleepAway.mp3<br/><br/>mp=Kalimba.mp3<br/>mp=ba.mp3<br/> 1 file(s) copied.<br/>mp=Maid with the Flaxen Hair.mp3<br/>mp=with the Flaxen Hair.mp3<br/> 1 file(s) copied.<br/>mp=SleepAway.mp3<br/>mp=Away.mp3<br/> 1 file(s) copied.<br/>Display Trim5<br/>ba.mp3<br/>with the Flaxen Hair.mp3<br/>Away.mp3<br/>C:test></body></html> | |