For the average user, deleting and renaming files through Windows/File Explorer is more than enough. However, there are some occasions where you might need to delete thousands of files at once, something which can be incredibly annoying and time consuming if done through Explorer. You may want to delete all of your music or your photo collections because you uploaded them to the cloud, for instance.
In addition to that, photography enthusiasts who upload their images to Windows will find themselves with dozens of folders containing pictures named “DSC_0001”, “DSC_0002” and so forth which is not exactly an ideal type of categorization. Thankfully, Windows offers the ability to rename and delete files in batches through Explorer, CMD, and PowerShell.
Batch Renaming
File Explorer
While File Explorer does offer an option to rename multiple files at once, it is not flexible at all so its usability is very limited. After selecting your files, right-click on one of them and select the Rename option. Note that you can use keyboard shortcuts to make your life easier. For instance, pressing Ctrl + A will select all items in the folder while holding down the Ctrl button will let you choose multiple files at once. After entering your desired name, the files will also get a new number assigned to them as you can see in the image below.
CMD
The Command Prompt offers more flexibility though it is mostly used to change the extension of multiple files at once. To rename files, you will need to point CMD into the right directory. To do that, right-click on the folder which contains the files you want to rename while holding down the Shift button and choose the “Open command window here” option. The basic syntax of the “Rename” command is as follows:
Ren FilePath FileName1 FileName2
As you can see, the basic command is incredibly simple but it comes incredibly useful once you realize it accepts both wildcard characters (* and ?). The “*” wildcard can stand in place of the entire name. For example, say that I want to change my .html files to .txt files. This is the command I would use:
Ren *.hmtl *.txt
This basically says that all HTML files in this directory, regardless of their name, should be turned into TXT files while retaining the same name.
The “?” wildcard can be used for more advanced operations as each question mark represents a single character. In the case of photo files, this is one of the commands you could use:
Ren DSC_????.jpg Birthday-Party_????.jpg
This will retain the numbering of the photos while renaming them to something more appropriate. Finally, you can also completely remove portions of a file’s name by using this template command:
Ren ???-FileCluster.HTML ???.HTML
This command will remove the second portion of the file’s name while keeping the first one intact.
PowerShell
As far as native Windows tools are concerned, PowerShell is the most flexible one when it comes to renaming files and folders. Since there is no option to “Open a PowerShell window here”, you will need to use the cd command instead. After launching PowerShell, just type cd “FilePath” (with quotes) and point the utility to the right directory.
Once you have done that, it is only a matter of using the right template to rename your files. To replace certain characters of your files, use this command:
Dir | Rename-Item –NewName { $_.name –replace “OriginalCharacter/s” “NewCharacter/s” }
This is an incredible command for massive directories, especially ones that contain photos as you can quickly replace the dreaded “DSC” with your own titles. Another useful parameter to remember here is Get-ChildItem. This simply parameter will let you bypass several restrictions, such as the fact that PowerShell’s Rename command does not normally accept wildcard characters. For instance, here is how you would replace all HTML extensions in a particular folder with TXT ones:
Get-ChildItem *.HTML | Rename-Item –NewName {$_.name –replace ‘\.HTML’, ‘.txt’ }
While these commands may seem a bit too advanced, you can check out several examples from Microsoft by typing the following into PowerShell:
Get-Help Rename-Item –Examples
Third-party tools
The above methods are certainly not for the faint of heart as anything that has to do with the command line is inherently complex, or at least it seems so. When it comes to renaming files, there are several utilities available but they mostly cater to an advanced crowd as they offer a multitude of options in not-so-friendly user interfaces. You can take a look at Advanced Renamer, bwRenamer, or Batch Rename. There are also more dedicated utilities that focus on specific file types such as PdfScanManager for your PDFs, Image Tuner and Trimto for your images, ID3 Renamer for audio files and Movie Renamer, for, well, your movies. Any app that you choose will feature a UI where you will have to insert the old and new text with several configurations available for you to apply. Just be mindful when you are dealing with sensitive files and try to make copies whenever possible.
Batch Deleting
CMD
For the process of mass deleting, all you really need is the command prompt. Here is how the basic structure of the delete command looks like:
Del /f /s /q FilePath > nul
Where
/f = Ignore read-only settings.
/s = Delete files in the subfolders.
/q = Delete without the confirmation prompt.
> nul = Creates a special file that automatically discards written data so the deletion process is sped up.
Now, as you might have already guessed, the delete command does not actually remove subfolders, only the items contained inside those subfolders. If you would like to delete the subfolders as well, you will need to run an additional command, like so:
Rmdir /s /q FilePath
Basically, you will usually need to run both commands in order to get rid of both the files and the folder structure, unless you want to do the latter manually.
Creating a batch delete file
If you find yourself in a situation where you have to constantly flush out a certain folder, such as the downloads folder of your browser, there is a way to automate the process so that you do not have to do everything manually each time.
Start by opening a text document in your computer. Then, enter the following lines in order:
Cd FilePath
Del * /s /q /f
This very basic batch file will let you delete all the files in that directory.
You can always add more commands, such as the aforementioned Remove Directory (rmdir) command but that is entirely up to you. When you are done with the file, click on File > Save As and select “All files” as the “Save as type”. Then, name your file as FileName.bat. The .bat extension is short for “batch” which is basically a file that contains at least one command. The greatest thing about these files is that you can also create shortcuts for them and thus you can place them wherever you want, even on your taskbar.