我有一个 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\""