Note that there are some explanatory texts on larger screens.

plurals
  1. POBatch rename issue when dealing with special characters in the filename
    text
    copied!<p>I have several hundred *.mp3 files in c:\files. There are all imaginable filenames in there like</p> <ul> <li>milad.mp3 (good behaving)</li> <li>hey you.mp3 (space in filename)</li> <li>systemofadown.mp3 (long filename)</li> <li>howdy(1).mp3 (parentheses in filename)</li> </ul> <p>and any combination of the last three conditions. I want to rename the files to 001-test.mp3, 002-mp3, ... It doesn't matter which file gets which name. have written a batch file to do the rename. Here is my code (with line numbers added):</p> <pre><code>01 rem @echo off 02 cls 03 set _number=%1 04 lfnfor on 05 06 :F1TO10 07 IF NOT EXIST *.mp3. goto end 08 if %_number% gtr 9 goto F10TO100 09 for /f %%a IN ('dir /b *.mp3') do rename %%~na.mp3 00%_number%-test.mp4 10 set /a _number +=1 11 goto F1TO10 12 13 :F10TO100 14 IF NOT EXIST *.mp3. goto end 15 if %_number% gtr 99 goto F100TO1000 16 for /f %%a IN ('dir /b *.mp3') do rename %%~na.mp3 0%_number%-test.mp4 17 set /a _number +=1 18 goto F10TO100 19 20 :F100TO1000 21 IF NOT EXIST *.mp3. goto end 22 if %_number% gtr 999 goto end 23 for /f %%a IN ('dir /b *.mp3') do rename %%~na.mp3 %_number%-test.mp4 24 set /a _number +=1 25 goto F100TO1000 26 27 :end 28 for /f %%a IN ('dir /b *.mp4') do rename %%~na.mp4 %%~na.mp3 29 echo Done </code></pre> <p>This code works fine for good behaving filenames (i.e. no spaces, no parentheses, no longer than 8 chars long). But if I have even a single file with a bad behaving filename, the script breaks (it loops endlessly until I stop it with Ctrl-C).</p> <p>The problem is obviously a filename issue. How can this be fixed? Any ideas? I'd greatly appreciate any help.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload