我尝试改进搜索概述,并在Windows XP命令提示符环境中查找批处理文件的内存 为了我之前的句子,我对我的搜索可能性感到不满,并且必须发布一个问题。
我尝试比较一些文本文件的名称,并在文本文件中写入相同的文字。在这样的启动环境中,我编写了以下批处理脚本来获取回显输出。
目标是
@echo off
setlocal enabledelayedexpansion
for /f "delims=" %%b in ('dir "C:\A Folder"') do set var=%%~nb & echo !var!
rem The output is the name of the files without extension. Now my question:
rem Is it possible to compare the above file names with some input
rem from a text file, for example like:
for /f "delims=" %%b in ('dir "C:\A Folder"') do set var=%%~nb & for /f %%a in (Textfile.txt) do (if !var!==%%a echo good else echo search)
rem That returns no output. I would like to know if there are possibilities
rem to do that? And if it is possible, how to revise this batch file?
endlocal disabledelayedexpansion
pause
祝你有美好的一天 斯蒂芬
答案 0 :(得分:0)
正确格式化代码会增加可读性:
for /f "delims=" %%b in ('dir /b /a-d "C:\A Folder"') do (
for /f %%a in (textfile.txt) do (
if "%%~nb"=="%%a" ( echo good ) else ( echo search )
)
)
我在/b
命令(仅显示名称,没有日期/时间/属性)和dir
中添加/a-d
以排除目录名。
你不需要在这里使用变量(!var!
)(但你可以,它可以正常工作)。
答案 1 :(得分:0)
这应该适用于拉丁字符 - 某些外国字符可能不起作用:
@echo off
for /f "delims=" %%b in ('dir /b /a-d "C:\A Folder\*.*" ') do find /i "%%~nb" < "textfile.txt" >nul && (echo "%%~nb" found) || (echo "%%~nb" not found)
pause