Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 使用bat文件将当前目录的完整路径写入文本文件_Batch File_Cmd - Fatal编程技术网

Batch file 使用bat文件将当前目录的完整路径写入文本文件

Batch file 使用bat文件将当前目录的完整路径写入文本文件,batch-file,cmd,Batch File,Cmd,我想完成- 1.读取文本文件的内容 2.将当前目录路径保存到变量 3.将目录中的文本字符串替换为路径 set mypath=%cd% set content= for /f "delims=:" %%i in ( 'type text.txt') do set. content=%content% %%i echo %content% set str=%content% set str=%str:string

我想完成-

1.读取文本文件的内容

2.将当前目录路径保存到变量

3.将目录中的文本字符串替换为路径

     set mypath=%cd%
     set content=
     for /f "delims=:" %%i in (
      'type text.txt') do set.     content=%content% %%i
      echo %content%
      set str=%content% 
      set str=%str:stringtoreplace= mypath %
      @echo off
      (echo %str%)>text.txt
您不能在正在读取的同一文件中写入

启用
延迟扩展
,然后像这样尝试:

@echo off
setlocal enabledelayedexpansion

set "mypath=%cd%"
set "stringtoreplace=toto"

(for /f "delims=" %%a in ('type test.txt') do (
   set "content=%%a"
   set "content=!content:%stringtoreplace%=%mypath%!"
   echo !content!
   ))>output.txt
如果需要使用相同名称的输出,请在末尾执行
重命名

del "test.txt"
ren "output.txt" "test.txt"