我有一個 Win10 腳本嘗試從我的備份中刪除 ...\User*\AppData\Local* 。它使用del /f /s /q
,但似乎並不總是有效。該命令運行,但沒有刪除任何內容。
例如,下面顯示了當我嘗試手動刪除資料夾“Apps”時會發生什麼 - 首先我嘗試使用del /f /s /q
,然後使用rmdir /s /q
。兩者都不起作用 - 資料夾仍然存在。
我做錯了什麼,如何刪除這些資料夾樹?
f:\mirrors\1day\ENOUGH\Users\dave\AppData\Local>dir
Volume in drive F is Backup 1 TB
Volume Serial Number is 427B-96E5
Directory of f:\mirrors\1day\ENOUGH\Users\dave\AppData\Local
09/27/2017 04:23 PM <DIR> .
09/27/2017 04:23 PM <DIR> ..
08/10/2016 02:10 PM <DIR> 3Dconnexion
06/11/2016 06:06 PM <DIR> ActiveSync
09/27/2017 02:00 AM <DIR> Adobe
08/05/2016 04:37 PM <DIR> Amazon
11/10/2014 04:53 PM <DIR> Apple
11/10/2014 04:54 PM <DIR> Apple Computer
09/27/2017 04:16 PM <DIR> Apps
0 File(s) 0 bytes
9 Dir(s) 457,199,636,480 bytes free
f:\mirrors\1day\ENOUGH\Users\dave\AppData\Local>del /f /s /q Apps
f:\mirrors\1day\ENOUGH\Users\dave\AppData\Local>dir
Volume in drive F is Backup 1 TB
Volume Serial Number is 427B-96E5
Directory of f:\mirrors\1day\ENOUGH\Users\dave\AppData\Local
09/27/2017 04:23 PM <DIR> .
09/27/2017 04:23 PM <DIR> ..
08/10/2016 02:10 PM <DIR> 3Dconnexion
06/11/2016 06:06 PM <DIR> ActiveSync
09/27/2017 02:00 AM <DIR> Adobe
08/05/2016 04:37 PM <DIR> Amazon
11/10/2014 04:53 PM <DIR> Apple
11/10/2014 04:54 PM <DIR> Apple Computer
09/27/2017 04:16 PM <DIR> Apps
0 File(s) 0 bytes
9 Dir(s) 457,199,636,480 bytes free
f:\mirrors\1day\ENOUGH\Users\dave\AppData\Local>rmdir /s /q Apps
The directory is not empty.
f:\mirrors\1day\ENOUGH\Users\dave\AppData\Local>dir
Volume in drive F is Backup 1 TB
Volume Serial Number is 427B-96E5
Directory of f:\mirrors\1day\ENOUGH\Users\dave\AppData\Local
09/27/2017 04:23 PM <DIR> .
09/27/2017 04:23 PM <DIR> ..
08/10/2016 02:10 PM <DIR> 3Dconnexion
06/11/2016 06:06 PM <DIR> ActiveSync
09/27/2017 02:00 AM <DIR> Adobe
08/05/2016 04:37 PM <DIR> Amazon
11/10/2014 04:53 PM <DIR> Apple
11/10/2014 04:54 PM <DIR> Apple Computer
09/27/2017 05:32 PM <DIR> Apps
0 File(s) 0 bytes
9 Dir(s) 457,199,636,480 bytes free
f:\mirrors\1day\ENOUGH\Users\dave\AppData\Local>
答案1
我測試了你的命令,del /f /s /q
子資料夾沒有被刪除,只有其中的檔案。我假設您的情況下仍然有子資料夾,請dir Apps
在刪除後進行驗證。
為了解決您的請求,您可以執行以下命令:
del /f /s /q Apps
rmdir /s /q Apps
答案2
我仍然不知道為什麼 del 和 rmdir 不能按預期工作,但這確實刪除了我無法刪除的資料夾:
powershell "rd -r \"Apple Computer\""