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

for %%j in (*.* Maps\*.*) do (
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
Oh yeah, you need to change the ren line to this: ren "%%~Fj" "!filename!%%~xj"
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
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\*.*".
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
