SoFunction
Updated on 2025-04-09

CMD's next command traversing the directory and deleting the code of the same file

If you accidentally install some garbage-making gadgets, the same garbage files will be generated under each drive letter in the system. For example, countless desktop_1.ini and desktop_2.ini have been generated in my system. The first solution I thought of at that time was to find all files using Windows' search tools and delete them together. This method can certainly be solved, but when searching, don't forget to check the search hidden files and hidden folders, otherwise you will not be able to search maliciously created garbage files.
Here is another simple method, with just one command, the same effect can be achieved. It iterates over the current drive letter and automatically deletes the found file.
Command format:
Copy the codeThe code is as follows:
I:\>for /F %i in ('dir desktop_1.ini desktop_2.ini /a /s /b') do (attrib -r -s -h %i && del %i)

'dir desktop_1.ini desktop_2.ini /a /s /b' All desktop_1.ini and desktop_2.ini can be found, including hidden files, and listed as full file path.
The for /F command analyzes each line of the records listed in the results. %i is the record content of each line, that is, the complete path of the file name here. The brackets after do are the command set for processing the file name. Here you can see that the file is first removed from read-only, system and hidden properties, so that it can be deleted using the delete command del.