如何逐行搜索文本文件中的字符串,并在找到匹配项时将找到匹配项的整行复制到变量中?
基本上,我有一个文本文件,其中包含文件夹中所有子文件夹的地址/路径。我想在这个文本文件中搜索一个字符串(该字符串将只匹配一行的一部分),如果有匹配项,我想将整行复制到一个变量中。
该字符串来自文件名,一旦文本文件中有匹配项,我想使用子文件夹地址将文件移动到那里。
这是我迄今为止所做的:
@ECHO off
::Reads all the folders and subfolders existing in the "root1" folder and writes the path for each foleder/subfolder into the "1.txt" file
dir /b /s /a:d "...\root1" > "...\1.txt"
::Reads all the files existing in "root2" folder and writes the path of each file into the "2.txt" file
dir /s /b "...\root2\" > "...\2.txt"
SETLOCAL EnableDelayedExpansion
::reads the last file path from the "2.txt" and asign it to a variable
for /f "delims=" %%x …Run Code Online (Sandbox Code Playgroud)