我在批处理文件中面临绝对路径和相对路径的问题...我的程序为
@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 INTEXTFILE=%%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%
它应该读取“D:\ TESTING \ a \ b \ try”目录中的所有txt和java文件,并将文本“hello”更改为“world”
答案 0 :(得分:0)
试试这个:
@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
)