Skip to content

Instantly share code, notes, and snippets.

@timiles
Created February 8, 2019 19:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timiles/661b4e74e4f0d3ad80ce5d29cd23b6e7 to your computer and use it in GitHub Desktop.
Save timiles/661b4e74e4f0d3ad80ce5d29cd23b6e7 to your computer and use it in GitHub Desktop.
PowerShell script to rename files ordered by last modified date
$files = Get-ChildItem | Sort-Object LastWriteTime
For ($i=0; $i -lt $files.Length; $i++) {
$from = $files[$i].Name
$to = "$($i.ToString('000')) $from"
Write-Host "Renaming `"$from`" to `"$to`""
Rename-Item $from $to
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment