【发布时间】:2015-11-19 22:25:31
【问题描述】:
我正在编写一个 Windows 批处理脚本,它编译作为参数传递给它的文件。这是我想做的:
- 转到每个文件位置。
- 在当前文件夹中搜索“makefile”。
- 如果找到,运行“make”并断开,否则转到父文件夹并重复第 2 步。
- 如果到达当前驱动器的根目录,则退出。
这是我到目前为止所能想到的:
输入:要编译的文件的完整路径列表。
示例:“D:/dir1/dir2/file1.cxx”“D:/dir1/dir3/file2.cxx”
@echo off
REM -- loop over each argument --
for %%I IN (%*) DO (
cd %%~dpI
call :loop
echo "After subroutine"
)
exit /b
:loop
REM -- NOTE: Infinite loop, breaks out when root directory is reached --
REM -- or makefile is found --
for /L %%n in (1,0,10) do (
if exist "makefile" (
echo "Building.."
make -s
echo "Exiting inner loop"
exit /b 2
) else (
if "%cd:~3,1%"=="" (
echo "Reached root...exiting inner loop..."
exit /b 2
)
REM -- Go to parent directory --
cd ..
echo "Searching one level up"
)
)
除此之外的所有工作文件 - 在遇到第一个“makefile”后,“exit /b 2”会导致批处理文件退出。我想要的是只有内部循环应该退出。 'exit /b 2' 应该根据this 工作,但由于某种原因它不是。谁能帮我解决这个问题?
【问题讨论】:
-
我不能用最小的批处理文件重现它,但是你代码中的循环有一个不正确的步骤参数
0,应该是1。 -
@wOxxOm : 循环步长为 0,因此无限运行。
标签: windows batch-file