0

与以下代码一样,我可以在任何 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
4

1 回答 1

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

这应该为您归档您的文件。

于 2013-09-18T06:19:37.973 回答