batch file - removing nonalphabet characters in a filename -


i have bunch of files , i'd remove characters not in alphabet. given filename of "home - noises (f).txt" want result of "home noises f.txt. batch file in samefolder , doesnt need recursive. have far:

@echo on setlocal enabledelayedexpansion %%# in (*.*) (     set myvar=%%~n#     set myvar=!myvar:"-"= !     ren "%%~n#" "!myvar!"     set myvar=!myvar:"("= !     ren "%%~n#" "!myvar!"     set myvar=!myvar:")"= !     ren "%%~n#" "!myvar!"     echo %%~n#>>text.txt ) pause&exit 

@echo off setlocal enabledelayedexpansion set preserve=abcdefghijklmnopqrstuvwxyz 1234567890 %%a in (*.*) (    set "filename=%%~na"    call :removechars filename newfilename=    if "!newfilename!" neq "%%~na" ren "%%a" "!newfilename!%%~xa" ) goto :eof   :removechars filename newfilename= set %2= :nextchar    set "char=!%1:~0,1!"    if "!preserve:%char%=!" neq "%preserve%" set "%2=!%2!%char%"    set "%1=!%1:~1!" if defined %1 goto nextchar exit /b 

the version below run faster previous one, requires several modifications in order manage special characters in remove string.

@echo off setlocal enabledelayedexpansion set remove=@#$()[] %%a in (*.*) (    set "filename=%%~na"    call :removechars filename newfilename=    if "!newfilename!" neq "%%~na" ren "%%a" "!newfilename!%%~xa" ) goto :eof   :removechars filename newfilename= set "%2=!%1!" set "remove2=!remove!" :nextchar    set "char=!remove2:~0,1!"    set "%2=!%2:%char%=!"    set "remove2=!remove2:~1!" if defined remove2 goto nextchar exit /b 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -