我正在编写一个脚本,该脚本应清空连接到计算机的所有设备/分区的Recycle.Bin
。
它通过测试可能的可用设备(从a到z字母)(未连接的设备除外)来做到这一点。
该脚本由于IF
循环中的FOR
语句而无法正常运行。我该如何解决?
@echo off
Setlocal EnableExtensions EnableDelayedExpansion
FOR %%G 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 (
SET nodev=none
fsutil fsinfo volumeinfo "%%G:" | find "Errore:" > nul
IF %ERRORLEVEL% EQU 0 SET nodev="%%G:"
IF "%%G:" NEQ "%nodev%" (
RD /s /q "%%G:\RECYCLED"
RD /s /q "%%G:\RECYCLER"
RD /s /q "%%G:\$Recycle.Bin"
)
)
最佳答案
试试这个代替fsutil。也是更清晰的代码。
@echo off
Setlocal EnableDelayedExpansion
FOR %%G 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 (
cd /d "%%G:" 2>nul
IF !ERRORLEVEL! EQU 0 (
RD /s /q "%%G:\RECYCLED"
RD /s /q "%%G:\RECYCLER"
RD /s /q "%%G:\$Recycle.Bin"
)
)
关于windows - Windows批处理文件-无法设置变量值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13955408/