0

My Problem is this:

I want to replace every Special character such as "@" in file names.

Example:

old file: test@home.txt
new file: test_home.txt

This should be done in a special chosen Folder including subfolders. The user should easily Change the Location (Folder).

Well, I will give this a try, but I am not sure how to:

%PATH% = G:\Tests\Folder

::Replace '@' with '_'
   SET _test=test@file.txt   
   SET _result=%_test:_=file
   ECHO %_result%          =test_file
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
donduc_jr
  • 19
  • 6

1 Answers1

0

setsyntax for replacing a string:

set "var1=my old hat"
set "var2=%var1:old=new%"
echo %var1% was better than %var2%

To get all txt-files:

for %%i in (*.txt) do (
  echo %%i
  rem substitution does not work with special %%i variable type
  set "oldname=%%i"
  set "newname=!oldname:@=_!"
  echo rename "!oldname!" "!newname!"
)

Why ! instead of %? See here

Community
  • 1
  • 1
Stephan
  • 53,940
  • 10
  • 58
  • 91