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
Its a wounderfoul

Should be new Filenames:

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 !


See More: Batch Replace Space in Filenames

Report •

January 4, 2011 at 04:33:29
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 •

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 ... ;-)


Report •
Related Solutions

Ask Question