Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the next command of CMD to traverse a directory and delete the same file

Shulou Source: shulou.com Published: 2022-06-03 07:53:22 11月15日 Update

This article will explain in detail how to use the next command of CMD to traverse the directory and delete the same files. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.

If you accidentally install some garbage-making gadgets and generate the same junk files 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 that comes to mind at that time is to find all the files using windows's search tool, and then delete them together. This method can certainly solve the problem. But don't forget to check hidden files and hidden folders when searching, or you won't be able to search for maliciously created junk files.

Here is another simple way to achieve the same effect with just one command. It traverses the current drive letter and automatically deletes the files found.

Command format:

The 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' can find all desktop_1.ini and desktop_2.ini, including hidden files, and list them as full file paths.

For / F command to analyze each line of records in the listed results,% I is the full path of the file name here, do is followed by parentheses on the file name processing command set, here you can see the file to remove read-only, system and hidden attributes, so that it can be deleted with the delete command del.

On "how to use CMD next command to traverse the directory and delete the same file" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, please share it out for more people to see.

Tags: File command search same spam article system directory one line content method tool file name more path manufacturing good practical code can reach Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Shulou Information Huawei OPPO Reno Microsoft