1

I have a test.txt with a lot of characters. However, I need to replace all of . to /. How can I do this? I tried using the follow code:

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION 
SET "sourcedir=C:\Users\HOME\Desktop"
SET "destdir=C:\Users\HOME\Desktop"
SET "filename=%sourcedir%\test.txt"
SET "outfile=%destdir%\outfile.txt"

(
FOR /f "usebackq delims=" %%a IN ("%filename%") DO (
 SET "line=%%a"
 SET "line=!line:.=/!"
 ECHO !line!
)
)>"%outfile%"

GOTO :EOF

Anyone can help me, please?

  • Did you got any error ? – Hackoo Sep 12 '17 at 19:39
  • I execute my .cmd file , the prompt is shown and close quickly and my outfile.txt is generated empty. – Alexsander Caproni Sep 12 '17 at 20:04
  • I see no problem with the batch. Insert a pause in front of the goto :eof or run the batch from an open cmd window to view any error messages. The dot in your replacement is missing –  Sep 12 '17 at 20:10
  • Check your paths are there correct in your case ? – Hackoo Sep 12 '17 at 20:27
  • 2
    Are you sure the input file is ASCII, and not Unicode? FOR /F cannot read Unicode. – dbenham Sep 13 '17 at 02:50
  • Possible duplicate of [How can you find and replace text in a file using the Windows command-line environment?](https://stackoverflow.com/questions/60034/how-can-you-find-and-replace-text-in-a-file-using-the-windows-command-line-envir) – Mofi Sep 13 '17 at 04:56

0 Answers0