[英]Find and delete desktop.ini files in every folder on a drive using a batch script
I want to find and delete every desktop.ini and Recycle Bin.BIN file on a network drive, H:, using a windows batch file.我想使用 windows 批处理文件查找并删除网络驱动器 H: 上的每个 desktop.ini 和 Recycle Bin.BIN 文件。 I currently have this:我目前有这个:
@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
Which works but for any file in a sub-folder with a space in the name it fails with a "cannot find file" error.哪个有效,但对于名称中有空格的子文件夹中的任何文件,它会因“找不到文件”错误而失败。 Any suggestions how to fix that?有什么建议可以解决这个问题吗?
solution that worked for me was 对我有用的解决方案是
create bat file "delete_all_desktop_ini.bat" with 使用创建bat文件“delete_all_desktop_ini.bat”
del /s /q /f /a ".\desktop.ini"
put it in a folder and run it 把它放在一个文件夹中运行它
it will delete all desktop inis in current directory and sub directories of this file. 它将删除此文件的当前目录和子目录中的所有桌面inis。
i put it in a project folder that is in google drive 我把它放在谷歌驱动器的项目文件夹中
Give this a test: 给这个测试:
I've altered the recycle bin name to what I see here in Windows 8. The name changes with different versions of Windows. 我已将回收站名称更改为我在Windows 8中看到的名称。名称随Windows的不同版本而变化。
@echo off
del /s /q /f /a "h:\desktop.ini"
del /s /q /f /a "h:\$Recycle.Bin\*.*"
The problem occurs because by default space is a delimiter for the for
command, but you can change this using the delims
option. 出现此问题的原因是默认空间是for
命令的分隔符,但您可以使用delims
选项更改此设置。 If you pick a character that won't ever appear in a file path then it should work fine: 如果您选择一个不会出现在文件路径中的字符,那么它应该可以正常工作:
@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
for /r "H:\" %%a in (desktop.ini $Recycle.Bin) do if exist "%%~fa" echo del /f "%%~fa"
尝试一下,使其工作从脚本中删除echo
。
del /s /q /f /a ".\desktop.ini" del /s /q /f /a ".\desktop.ini"
it should works as charm save file.bat put it in any folder it will delete ini files in folders and sub folders它应该作为魅力保存文件.bat 将它放在任何文件夹中它将删除文件夹和子文件夹中的ini文件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.