Skip to content

Instantly share code, notes, and snippets.

@Dan1el42
Last active September 5, 2015 15:28
Show Gist options
  • Select an option

  • Save Dan1el42/c1a05ab044254f7898da to your computer and use it in GitHub Desktop.

Select an option

Save Dan1el42/c1a05ab044254f7898da to your computer and use it in GitHub Desktop.
Param
(
[Parameter(Mandatory)]
[System.String]
$Path,
[System.String]
$Filter = '*.jpg',
[System.String]
$NewNameFormat = 'DSC_{0:d3}.jpg'
)
[IO.FileInfo[]]$Files = Get-ChildItem -Path $Path -Filter $Filter -File |
Sort-Object -Property LastWriteTime
for ($i = 0; $i -lt $Files.Count; $i++)
{
$NewName = $NewNameFormat -f ($i + 1)
# Remove -WhatIf if you want files to actually be renamed
Rename-Item -Path $Files[$i].FullName -NewName $NewName -WhatIf
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment