Skip to content

Instantly share code, notes, and snippets.

@chgeuer
Created November 21, 2012 20:07
Show Gist options
  • Select an option

  • Save chgeuer/4127323 to your computer and use it in GitHub Desktop.

Select an option

Save chgeuer/4127323 to your computer and use it in GitHub Desktop.
PS1 Rename
function Rename-ItemsPrepend {
[CmdletBinding()]
param
(
[Parameter(Mandatory=$True,
ValueFromPipeline=$False,
ValueFromPipelineByPropertyName=$True,
HelpMessage='Which number should be first prefixed')]
[int]$start
)
begin {
write-verbose "Renaming files"
}
process {
write-verbose "Beginning process loop"
$i = $start
Get-ChildItem | Sort-Object -Property CreationTime | foreach ($_) {
$nn = [System.String]::Format("{0:d2}__{1}", $i++, $_.Name)
Rename-Item -Path $_.FullName -NewName $nn
}
}
}
Set-Alias -Name renumber -Value Rename-ItemsPrepend
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment