Problem with Absolute path and Relative path in batch file
I am facing problem with Absolute path and Relative path in batch file...I have program as
@echo off
setlocal enabledelayedexpansion
set LOCATION=D:\TESTING\a\b\try
set OUTTEXTFILE=test_out.txt
set SEARCHTEXT=hello
set REPLACETEXT=world
FOR /r %LOCATION% %%x IN (\*.txt,\*.java) (
DO echo %%x
SET INTEXT开发者_如何学PythonFILE=%%x
)
for /f "tokens=1,* delims=¶" %%A in ( '"type %INTEXTFILE%"') do (
SET string=%%A
SET modified=!string:%SEARCHTEXT%=%REPLACETEXT%!
echo !modified! >> %OUTTEXTFILE%
)
del %INTEXTFILE%
rename %OUTTEXTFILE% %INTEXTFILE%
It should read all txt and java files from "D:\TESTING\a\b\try" dir and change the text 'hello' to 'world' in them
Try this:
@echo off
setlocal enabledelayedexpansion
set LOCATION=D:\TESTING\a\b\try\
set OUTTEXTFILE=temp.txt
set SEARCHTEXT=world
set REPLACETEXT=hello
FOR /r %LOCATION% %%x IN (*.txt,*.java) do (
FOR /f "tokens=1,* delims=¶" %%A in ( '"type %%x"') do (
SET string=%%A
SET modified=!string:%SEARCHTEXT%=%REPLACETEXT%!
echo !modified! >> %OUTTEXTFILE%
)
del %%x
copy %OUTTEXTFILE% %%x
del %OUTTEXTFILE%
echo location %%x
)
精彩评论