我尝试使用以下脚本来搜索文件位于哪个驱动器,但无法显示结果。请帮忙看看哪里出了问题。提前致谢。
for /f tokens^=1*delims^=: %%i in ('
fsutil fsinfo drives')do set "_drvs=%%~j"
for /f tokens^=*^delims^=? %%i in ('
call dir/b/a-d/s %_drvs:\=\BatchScripts.txt% 2^>nul
')do set "_fpath=%%~dpi" && set "_file=%%~dfi" && set "_drive=%%~di" && goto %:^)
%:^)
echo\Use "%_fpath%" and "%_file%" and "%_drive%"
PAUSE
新建和修改
if exist D:\sources\sxs\ (
echo The source drive is Drive D
pause
dism /online /enable-feature /featurename:netfx3 /All /LimitAccess /Source:D:\sources\sxs /NoRestart
) else (
if exist E:\sources\sxs\ (
echo The source drive is Drive E
pause
dism /online /enable-feature /featurename:netfx3 /All /LimitAccess /Source:E:\sources\sxs /NoRestart
) else (
if exist F:\sources\sxs\ (
echo The source drive is Drive F
pause
dism /online /enable-feature /featurename:netfx3 /All /LimitAccess /Source:F:\sources\sxs /NoRestart
)
)
)
答案1
我假设您要搜索的文件是信:\来源\sxs文件夹,并且您正在尝试查找它所在的驱动器,对吗?如果是,我建议您这样做:
:scan
for %%a in ( A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ) do (
if /i exist ”%%a:\sources\sxs\” (
echo The source letter drive is Drive %%a:
pause
rem here you will put commands that are executed only in the case that \sources\sxs\ is found on the "%%a" drive
goto :success
rem make sure to add a "success" label when the drive is found and the commands are executed to exit from the loop
)
)
echo No drive seems to contain the \sources\sxs folder...
echo Press ENTER to scan again
pause>nul
goto :scan
:success
echo Operation completed successfully!
pause
exit
如果我错了,我很抱歉,我是超级用户新手,还不能发表评论。我本来想留下一条评论,以确保我理解了这个问题,但我现在还不能。希望这能有所帮助!