Deleting all files that do not match a certain pattern - Windows command line

explanation

When it comes to managing files, especially in a professional setting, one of the most useful operations to know how to perform is how to select and delete all files that do not match a certain pattern. This can be done on a Windows command line, and it is a helpful tool for IT administrators who need to quickly clean up a cluttered drive or folder.

The Windows command line is an important tool for IT administrators, as it provides an easy way to quickly execute tasks that would otherwise take much more time. This includes things like running programs, changing environment variables, and manipulating files. While the graphical user interface of Windows can be used to manage files, the command line provides a much faster way to accomplish tasks.

To delete all files that do not match a certain pattern on a Windows command line, the administrator must first open a command prompt. This can be done by pressing the Windows key + R and then entering “cmd” into the search box. Once the command prompt is open, the administrator can use the “del” command to delete any files that do not match the desired pattern.

For example, to delete all files that do not have the “.txt” extension, the administrator would type “del *.* /f /a-d *.txt” into the command prompt. This command will delete all files in the current directory that do not have the “.txt” extension. The “/f” flag stands for “force”, which means that the deletion will be done even if the files are marked as “read-only”. The “/a-d” flag indicates that only files should be deleted, not directories.

It is important to note that this command will not delete any files that are hidden. To delete hidden files, the administrator must use the “/a:h” flag instead of the “/a-d” flag. This will allow the command to delete all files, including those that are marked as hidden.

In addition to the “del” command, the administrator can also use the “dir” command to list all files in a directory. This is useful for ensuring that the desired files are being deleted. For example, to list all files in the current directory that have the “.txt” extension, the administrator would type “dir *.txt” into the command prompt. This will list all files in the current directory that have the “.txt” extension.

In conclusion, deleting all files that do not match a certain pattern on a Windows command line is a useful operation for IT administrators. This process can be accomplished using the “del” command, and the administrator can use the “dir” command to list all files in a directory. By using these two commands, IT administrators can quickly and easily delete any undesired files.

Inquire Now

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Find your next full or part-time role here

ScaleDesk can either help you find your next full time gig or a part time side gig where you can create extra income!

Onboard with us once
Skip HR screening and go to the final interview with with only your resume and a video interview you never have to redo
Get paid electronically every month for the hours you work
We will be your reference even if you work for us once

IT Teams: Use ScaleDesk to augment your team

Schedule Demo