Articles

Search and replace empty spaces in

August 17, 2008 at 14:37:36
Specs: windows XP, amd2 5200+ 3GB ram

Hi,

I need to replace filenames having spaces and dots with underscore using a .bat script

example:

I need to convert filenames like Web News 04-08-2008.docx to Web_News_04-08-2008.docx

But i need it also to be able to look and replace in (Sub) Maps

This is the script i used for testing and it works perfect but it does not change any file names in the Sub map what is good is that it didn't change the name of the Sub map
Here is the Script:

@echo off
setlocal enabledelayedexpansion
for %%j in (*.*) do (
set filename=%%~nj
set filename=!filename:.=_!
set filename=!filename: =_!
if not "!filename!"=="%%~nj" ren "%%j" "!filename!%%~xj"
)


Can someone kindly help?

Thank you



See More: Search and replace empty spaces in

Report •


#1
August 17, 2008 at 19:32:47

for %%j in (*.* Maps\*.*) do (


Report •

#2
August 17, 2008 at 21:28:48

Sorry Razor2.3

it didn't work i tested it and all files, in
the sub map stayed un touched.

thanks any way for your help


Report •

#3
August 17, 2008 at 21:42:55

Oh yeah, you need to change the ren line to this:
ren "%%~Fj" "!filename!%%~xj"


Report •

Related Solutions

#4
August 18, 2008 at 02:12:23

Sorry Razor it still does not work with Sub maps i made the changes like you said but the result is still the same only the files in the directory it self are changed but nothing in the sub map, Here is the code changed like you said.

@echo off
setlocal enabledelayedexpansion
for %%j in (*.* Maps\*.*) do (
set filename=%%~nj
set filename=!filename:.=_!
set filename=!filename: =_!
if not "!filename!"=="%%~nj" ren "%%~Fj" "!filename!%%~xj"
)


Thank you for your help


Report •

#5
August 18, 2008 at 17:37:50

You didn't get rid of the IF statement. Not that it changes anything.

I don't know why it's not working for you; the code you posted works for me. Unless you mean "a subdirectory called 'sub maps,'" and not, "a subdirectory called 'maps.'" If that's the case, use "sub maps\*.*".


Report •

#6
August 19, 2008 at 00:59:12

I have made the script work so that it looks and changes file names in other sub maps but my problem is that this script is going to be placed in a Relative map on a remote server.

so the scrip is now like this with a designated starting map(g:\test) to work from, now that starting map should be the relative map.


@echo off
setlocal enabledelayedexpansion
for /r g:\test %%j in (*.*) do (
set filename=%%~nj
set filename=!filename: =-!
if not "!filename!"=="%%~nj" ren "%%~Fj" "!filename!%%~xj"
)

thank you for helping me


Report •


Ask Question