根据我的评论,这是一个嵌套For
循环的示例,应该按照要求执行:
For /F "Tokens=*" %%A In ('MountVol^|Find ":\"') Do For /F "Delims=" %%B In ('Dir /B/S/AD-S-L "%%ATemporaryFolder" 2^>Nul') Do RD /S/Q "%%B" 2>Nul
外部For
循环运行MountVol
命令,该命令将安装的驱动器路径返回为%%A
. 嵌套For
循环对TemporaryFolder
位于%%A
.
编辑
这是同一例程的多行版本,其中添加了消息:
@Echo Off
Set "objFolder=TemporaryFolder"
Echo Please be patient...
For /F "Tokens=*" %%A In ('MountVol^|Find ":\"') Do (
Echo Deleting directories named %objFolder% from %%A
For /F "Delims=" %%B In ('Dir /B/S/AD-S-L "%%A%objFolder%" 2^>Nul') Do (
Echo Deleting %%B
RD /S/Q "%%B" 2>Nul && Echo Successfully deleted %%B
)
)
Pause
您应该只在线修改objFolder
名称2
。
而不是MountVol
,这个PowerShell
用于获取驱动器,并匹配系统和重新分析点,(考虑到您需要适当的权限才能删除系统目录):
@Echo Off
Set "objFolder=TemporaryFolder"
Echo Please be patient...
For /F "Tokens=*" %%A In (
'PowerShell -NoP "GDr -P FileSystem|?{!$_.Used -Eq ''}|Select -Exp Root"'
) Do (Echo Deleting directories named %objFolder% from %%A
For /F "Delims=" %%B In ('Dir /B/S/AD "%%A%objFolder%" 2^>Nul') Do (
Echo Deleting %%B
RD /S/Q "%%B" 2>Nul && Echo Successfully deleted %%B
)
)
Pause