与下面的代码一样,我可以在任何C盘或D盘中搜索并获取文件夹的路径。假设我有一个文件即psqlwithdata.dump在任何一个驱动器中的未知位置的C或D驱动器然后如何在C或D驱动器中获得ie psqlwithdata.dump的路径?
@echo off
for /f "delims=" %%a in (' dir "c:\demo22112" /b /s /ad ') do if /i "%%~nxa"=="demo22112" set "folder=%%a"
if not defined folder for /f "delims=" %%a in (' dir "d:\demo22112" /b /s /ad ') do if /i "%%~nxa"=="demo22112" set "folder=%%a"
echo "%folder%"
pause
答案 0 :(得分:2)
@echo OFF
SETLOCAL
SET "folder="
FOR /r "C:\" %%a IN (psqlwithdata.dump) do IF EXIST "%%a" SET "folder=%%~dpa"&GOTO got1
FOR /r "D:\" %%a IN (psqlwithdata.dump) do IF EXIST "%%a" SET "folder=%%~dpa"&GOTO got1
:got1
echo "%folder%"
GOTO :EOF
这应该为你准备文件。