Created
April 8, 2025 01:44
-
-
Save lrckt/532cc393432be5a15cbe913e39b7e3bc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set the path to the folder containing the files | |
$folderPath = "C:\Path\To\Your\Folder" | |
# Get all files in the folder | |
Get-ChildItem -Path $folderPath -File | ForEach-Object { | |
$file = $_ | |
# Use regex to match the pattern ending with _numbers (e.g. _20230230230) | |
if ($file.Name -match "^(.*?\.\w+)_\d+$") { | |
$newName = $matches[1] | |
# Full path for new name | |
$newFullPath = Join-Path -Path $folderPath -ChildPath $newName | |
# Rename the file | |
Rename-Item -Path $file.FullName -NewName $newFullPath | |
Write-Host "Renamed '$($file.Name)' to '$newName'" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment