使用批处理脚本查找和删除驱动器上每个文件夹中的desktop.ini文件

use*_*823 3 windows hidden batch-file delete-file

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

@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
Run Code Online (Sandbox Code Playgroud)

哪个适用于子文件夹中的任何文件,其名称中的空格失败并显示"无法找到文件"错误.任何建议如何解决?

Shi*_*kin 9

对我有用的解决方案是

使用创建bat文件"delete_all_desktop_ini.bat"

del /s /q /f /a ".\desktop.ini" 
Run Code Online (Sandbox Code Playgroud)

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

它将删除此文件的当前目录和子目录中的所有桌面inis.

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


fox*_*ive 6

给这个测试:

我已将回收站名称更改为我在Windows 8中看到的名称.名称随Windows的不同版本而变化.

@echo off
del /s /q /f /a "h:\desktop.ini" 
del /s /q /f /a "h:\$Recycle.Bin\*.*"
Run Code Online (Sandbox Code Playgroud)


Jon*_*ter 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
Run Code Online (Sandbox Code Playgroud)