gpt4 book ai didi

windows批处理FOR循环查找文件夹

转载 作者:可可西里 更新时间:2023-11-01 14:45:19 25 4
gpt4 key购买 nike

伪代码:

path = ".";
for(;;)
{
if(exist(path + "/file.exe")
break;
path += "/..";
}

基本上,我有一个从文件夹运行的脚本,该文件夹比包含 file.exe 的文件夹深几层,我需要找到该文件夹​​的路径。

为了快速解决问题,我将其添加到我的 bat 文件中:

set PATH=..;..\..;..\..\..;..\..\..\..;%PATH%

是否有正确的方法来迭代文件夹并检查其中是否存在文件?

最佳答案

我会尝试类似的东西

pushd
:loop
if exist file.exe goto :found
set lastdir=%cd%
cd ..
if "%cd%" EQU "%lastdir%" goto :notfound
goto :loop
:notfound
echo file.exe not found!
popd
goto :eof
:found
set file=%cd%\file.exe
popd

关于windows批处理FOR循环查找文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12080638/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com