Thursday, October 6, 2011

New script for delete %20 in batch

Now have added a few aesthetics by reporting the number of files renamed.

Warning: Use at own risk

The script:

@echo off
setlocal EnableDelayedExpansion
set /a a=0
for /f "delims=" %%I in ('dir /b ^| find "%%20"') do (
set var01=%%I
set var02=!var01:%%20=" "!
call :ren
echo Successfully renamed %a% files.
ren "%var01%" %var02%
if %ERRORLEVEL%==0 echo Renamed %var01%
if %ERRORLEVEL%==0 set /a a=%a%+1

1. Copy the script above and paste into notepad

2. Save it as "spaceReplacer.bat", file type: All Type.

3. Put it in the same folder as the files with %20

4. and run

5. Success!

No comments: