Special Characters in Dos File names?

Microsoft Windows 7 home premium
July 8, 2012 at 17:59:42
Specs: Windows 7, 533Mhz / 192 MB
CH wrote:

I" do not know bat commands and I need to go through a folder structure and recursevly
find all files and rename them, I mean if the file name has special characters
( ?<>@#$ also space) I need to rename them into an underscore."

C:\test>type 2oldnew.bat
@echo off
echo newname > newname.txt
echo.
echo. > one.txt
setlocal enabledelayedexpansion
echo.
for /f %%i in (char.txt) do (
rem echo i=%%i
findstr %%i oldname.txt > one.txt
set /p str=<one.txt
set str=!str:%%i=_!

echo !str! >> newname.txt
)

findstr one oldname.txt > one.txt
set /p str=<one.txt


set str=%str: =_%

echo %str% >> newname.txt

echo.
type oldname.txt
echo.
type newname.txt
rem use copy, rename or move.
rem copy is safest until procedure works for you
C:\test>
C:\test>2oldnew.bat

file one.txt
file#two.txt
file?four.txt
file<five.txt
file>six.txt
file@seven.txt

newname
file_two.txt
file_four.txt
file_five.txt
file_six.txt
file_seven.txt
file_one.txt

C:\test>

Bill


See More: Special Characters in Dos File names?

Report •

#1
July 9, 2012 at 01:20:19
What is your question?

I'm not even sure I see the point because as far as I know, it's not possible to create files with special characters in the filename.

Tony


Report •
Related Solutions


Ask Question