Batch Replace Space in Filenames

January 4, 2011 at 02:35:54
Specs: Windows XP
Hi all,

I want to replace spaces and points (only before the extention) in Filenames with another char e.g. with an underscore.

Orginal Filenames:
007 James Bond.info
The Crow.info
Its a wounderfoul Life.info
Epica.2007.The.Divine.Conspiracy.info
Sirenia.2009.The.13th.Floor.info

Should be new Filenames:
007_James_Bond.info
The_Crow.info
Its_a_wounderfoul_Life.info
Epica.2007_The_Divine_Conspiracy.info
Sirenia_2009_The_13th_Floor.info

I know that i can use VBScript but i want to do thin in an Batch , if its possible ...?
Has anyone a idea ?

Thanks & take care !

Helmut


See More: Batch Replace Space in Filenames

Report •


#1
January 4, 2011 at 04:33:29
@ECHO OFF
SETLOCAL EnableDelayedExpansion

FOR /f "tokens=*" %%a IN ('DIR /b "*.info"') DO (
SET Var=%%~na
SET Var=!Var: =_!
SET Var=!Var:.=_!
REN "%%a" "!Var!.info"
)

Can I put a question here?


Report •

#2
January 4, 2011 at 08:41:00
... good Job Matt , it should be works in the normal Way ... great ...
but on my side i get an error "Can't find the file ..." ,
I viewed both strings (the value of Var and the filename over clipboard) within the HEX-Editor and there is one char different . The "-" from the Batch is HEX: 2D and in the 'real filename' the "-" is HEX: 96

So he can't find it , also he can't rename it .... mh ??

Thank you very much , you save me a lot of time , to find out how it works ...

Mabye you have a hint to solve the char problem ... i will try to fix it , ... hope Google helps me ... ;-)

Cheers
Helmut


Report •
Related Solutions


Ask Question