1

我想编写一个函数,该函数是在另一个目录(共享驱动器)中使用另一个嵌入式命令 %recent% 执行“查找”命令。

下面是思路:

REM Take in log file name input eg. "result_10030" = %1 to search for all result_10030*.log = %1*.log
REM Use the following to list the files matching result_10030*.log

for /f "delims=" %%x in ('dir /d /od /b %1*.log') do set recent=%%x
echo %recent%

REM Use %recent% as the file to perform find
REM Take in %2 as share drive path

find "PASSED" %2%recent%

显然它不工作。

您的建议将不胜感激!:)

4

1 回答 1

0

DIR/D/B选项不兼容 - 该/B选项覆盖该/D选项。

您的 FOR /F 循环还需要知道要查看的路径,而不仅仅是您的 FIND commnad。最简单的做法是将当前目录更改为所需的路径。

pushd %2
for /f "delims=" %%x in ('dir /d /od /b "%~1*.log"') do set "recent=%%x"
echo %recent%
find "PASSED" "%recent%"
set rtn=%errorlevel%
popd
exit /b %rtn%
于 2012-08-23T04:22:42.313 回答