Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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?

like image 941
user2830823 Avatar asked Sep 30 '13 10:09

user2830823


1 Answers

solution that worked for me was

create bat file "delete_all_desktop_ini.bat" with

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.

i put it in a project folder that is in google drive

like image 63
Shimon Doodkin Avatar answered Nov 15 '22 04:11

Shimon Doodkin