Search code examples
batch-rename

Removing group of random characters


Ok so I have these files

File1 (37362717) File2 (29190171) File3 (35515714)

How would a script look to remove the (*) portion of the name?


Solution

  • If you can use powershell, use this command in the directory containing all your files that need rename:

    Get-ChildItem File* | Rename-Item -NewName { $_.name -replace " \(\d+\)", "" }
    

    This command renames all files whose name starts with "File" in current directory so that the "space and then parentheses with numbers inside" (\(\d+\)) part will be removed.

    Check example 4 in this link to understand how this command works.