Let's say you had 4 files...

  1. Filename.043.-2854.exe
  2. Filename.044.-2123.exe
  3. Filename.045.-3518.exe
  4. Filename.046.-6518.jpg

...but you want the ones ending in ".exe" to look like this...

  1. Filename-2854.exe
  2. Filename-2123.exe
  3. Filename-3518.exe
  4. Filename.046.-6518.jpg

By using the following in Powershell, you can do that.

Get-ChildItem -Path $directory/to/files -Filter '*.exe' | Rename-Item -NewName { $_.Name -replace '.\d{4}' }

Notice file #4 wasn't changed. That is because we filtered by extension so that only the files ending in ".exe" are modified.

© 2017. All Rights Reserved.

Proudly published with Ghost