Windows CMD FINDSTR字符串和副本文件 [英] Windows CMD FINDSTR STRING AND COPY FILE
问题描述
我有一个文件夹,该文件夹的子文件夹包含txt和pdf文件.每个txt文件都有一个Pdf文件,其名称几乎相同.
I have a folder with subfolders include txt and pdf files. There is a Pdf file for each txt file which has nearly same name.
例如;每个 ABC_R10.txt ->都有一个 ABC).pdf 文件.
For example; for each ABC_R10.txt --> there is a ABC).pdf file.
在Windows 10中,带有批处理文件
In Windows 10, with a batch file,
我想使用FINDSTR命令在.txt文件中搜索特定的字符串,然后将包含我的字符串的文件复制到当前文件夹中.到目前为止,我已经获得了正确的代码.
I want to search specific string in a .txt file with FINDSTR command, and copy files, which contain my string, into current folder. I achieved proper code until this point.
CLS
@ECHO OFF
ECHO FIND BUKUM
findstr /m /s /i /p /c:"BUKUM" *.txt > logfile.xls
for /f "delims=" %%a in ('findstr /m /s /i /p /c:"BUKUM" *.txt') do ^
copy "%%a" "%cd%"
if errorlevel 1 echo nothing found.
PAUSE
CLS
EXIT
但是我想找到完全匹配的文件名,但是得到名称相似的pdf文件,而不是txt文件.
But I want to find file name of exact match but get pdf file with similar name, not txt file.
我必须获取 ABC_R10.txt 的 ABC ,并添加).pdf 字符串并获取 ABC).pdf
I have to get ABC of ABC_R10.txt and add ).pdf string and get ABC).pdf
_R 的子字符串出现在每个.txt文件中.
Substring of _R occurs each .txt file.
我该如何实现?
推荐答案
仅基于您现在编辑的问题:
Based solely on your now edited question:
@For /F "Delims=_" %%A In ('FindStr /SPMIC:"BUKUM" *.txt') Do @Copy /Y "%%A).pdf">Nul
这篇关于Windows CMD FINDSTR字符串和副本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!