Background
I am searching a large directory for files with certian strings of characters in their names. I only want to know if the files exsist in said directory.

Problem Description
Right now I am inputing the following code into windows 7 cmd prompt

dir T162511*.dwg /s /b >> searchresults.txt 2>>&1

T162511.dwg is not found and the phrase "File Not Found" is inputted to a text file, also if you notice I am putting the found file with similar name's path of the files location in the text file as well provided that it was found.

Question
How can I get cmd prompt to output [Drive:]/Path/FileName.dwg and "File Not Found" to a text file in one line?

有帮助吗?

解决方案

dir T162511*.dwg /s /b >> searchresults.txt 2>nul || (>>searchresults.txt echo T162511.dwg not found)

If dir command does not find the indicated file, it raises errorlevel and the code after || is executed

EDITED - Code adapted to comments. Assuming it will be included in a batch file, and the drive:\path\to\file is inside a variable (maybe defined from some parameters to batch file), this should to the work

set "filesToFind=c:\somewhere\T162511*.dwg"
dir /s /b /a-d "%filesToFind%"  >> searchresults.txt 2>nul || (>>searchresults.txt echo %filesToFind% not found)
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top