2013-09-30 37 views
2

我想使用Windows批处理文件查找并删除网络驱动器H:上的每个desktop.ini和Recycle Bin.BIN文件。目前,我有这样的:使用批处理脚本在驱动器上的每个文件夹中查找并删除desktop.ini文件

@echo About to delete all desktop.ini and Recycle Bin.BIN files from H:, press Ctrl+C to cancel or Enter to continue. 
@pause 
@H: 
@for /f "usebackq" %%i in (`dir /s /b /x /A:H ^| find "desktop.ini"`) do del /A:H "%%i" 
@for /f "usebackq" %%i in (`dir /s /b /x /A:RH ^| find "Recycle Bin.BIN"`) do del /A:RH "%%i" 
@echo Deleting complete, press any key to exit. 
@pause 

哪些工作,但在子文件夹中的所有文件的名称中的空间它失败,出现“找不到文件”的错误。任何建议如何解决这个问题?

回答

1

发生该问题是因为默认情况下,空间是for命令的分隔符,但您可以使用delims选项更改此选项。如果你选择的永远不会出现在文件路径中的字符,则应该很好地工作:

@echo About to delete all desktop.ini and Recycle Bin.BIN files from H:, press Ctrl+C to cancel or Enter to continue. 
@pause 
@H: 
@for /f "usebackq delims=|" %%i in (`dir /s /b /x /A:H ^| find "desktop.ini"`) do del /A:H "%%i" 
@for /f "usebackq delims=|" %%i in (`dir /s /b /x /A:RH ^| find "Recycle Bin.BIN"`) do del /A:RH "%%i" 
@echo Deleting complete, press any key to exit. 
@pause 
6

这给测试:

我已经改变了回收站的名称是什么我在这里看到在Windows 8中。 该名称随不同版本的Windows而变化。

@echo off 
del /s /q /f /a "h:\desktop.ini" 
del /s /q /f /a "h:\$Recycle.Bin\*.*" 
0
for /r "H:\" %%a in (desktop.ini $Recycle.Bin) do if exist "%%~fa" echo del /f "%%~fa" 

试试吧,使其工作从脚本删除echo

6

的解决方案,为我工作是

创建批处理文件“delete_all_desktop_ini.bat” 与

del /s /q /f /a ".\desktop.ini" 

把它放在一个文件夹中,然后运行它

,将删除所有桌面在核信息系统当前目录和该文件的子目录。

我把它放在谷歌驱动器上的项目文件夹中

相关问题