So you have a folder with let’s say, 1000 pictures with duplicates, maybe your camera was taking JPG photos and RAW photos, but you only want to keep the RAW ones, how do you go about deleting them all without having to click them all? Well in this post I will be showing you how to do just that, delete all files of a certain type in a directory.
First things first is you will need to open Command Prompt as an Administrator and navigate to the directory that has the files, we have a guide on that here, but all you need to do is type ‘cd file/path‘ where file/path is the whole path to the folder e.g. C:\Users\TestUser\Pictures.
Now for the purpose of this post I’m going to be deleting Word documents but this can easily be changed to delete any file type, such as the JPG’s in the scenario above.
The command you will need is ‘del *.docx‘ where docx is any file type that you want to delete. We may also want to throw some switches in there too such as:
- /s which deletes specified files from the current directory and all subdirectories. It also displays the names of the files as they are being deleted.
- /f forces the deletion of read-only files.
- /q specifies quiet mode, you won’t get a confirmation prompt when deleting the files.
- /p asks you for permission before deleting each file, useful if you’re not too sure what you want to delete.
All information on these switches is from the Microsoft website.
So your command might look something like this ‘del *.docx /f /q‘
The asterisk is a wildcard so it will delete anything in the specified directory with the file type of ‘docx‘.
You can use the wildcard listed above with the ‘dir‘ command to list all of the files that will be deleted before you commit to deleting them, it would look a little something like ‘dir *.docx‘ where docx is any file type you wish to find.
Running the command
So I’ve spoken about all of this stuff, how about we put it into action?
Here are the Word files we want to delete:
We run the command ‘del *.docx /f /q‘
Voila! All of the docx files have been deleted but not the PDF that was in there.
If we add the /s switch to the command then it will list the files that have been deleted like so:
Run the command ‘del *.filetype‘, from the directory the files are in.
Filetype is the file type you wish to delete and then add your preferred switches e.g. ‘del *.docx /s /f /q‘