Search code examples
filefile-renamebatch-rename

How Can I Batch Rename Files in a Folder?


I have a folder with hundreds of files. I need to rename the files in this folder one by one; but this takes a lot of time. I did some research and found that it can export names from a text file to files in any folder I want. But the videos contained insufficient information for me to implement it.

What I've been able to do so far:

  • I was able to transfer file names to TXT file with CMD command. Note: After exporting the filenames I found some errors in the sorting. You can see the related error in the "Example Files II" section.

Example files I:

Files and their real names.

Example files II:

I exported the file names to txt file with CMD; but the order of the fil names is not the same as in the TXT file with slight differences.

Note: This is not a big problem for now; but I would like to know if there is a way to do the correct sorting.

Export File Names

Example files III:

I batch corrected the filenames with EmEditor. Now I need to automatically replace these names with the files in the folder. Here I don't know how to do this. If anyone can provide practical information on this subject, I would be glad.

Corredted File Names


Solution

  • You can use Powershell and a regular expression to rename files. Go to the folder in Explorer, select Open Windows Powershell on the File menu, and enter the following:

    Get-ChildItem *.zip | Rename-Item -NewName { $_.Name -replace '-[0-9]{4}-[0-9]{2}-[0-9]{2}(-[0-9]{2}-[0-9]{2}-[0-9]{2}\-utc)?\.zip$','.zip' }
    

    enter image description here

    References: