Skip to content

Instantly share code, notes, and snippets.

@cromwellryan
Created May 25, 2011 16:01
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 cromwellryan/991245 to your computer and use it in GitHub Desktop.
Save cromwellryan/991245 to your computer and use it in GitHub Desktop.
Prepend Zeros to files via PS
function number-part($name) { return $name.Split(' ')[0] }
function prepend-if-needed($fi) {
$numberpart = number-part $fi.Name
$potentialnewname = "0" + $fi.Name
if( $numberpart.length -lt 2 ) { ren -Path $fi.FullName -NewName $potentialnewname }
}
ls | foreach { prepend-if-needed $_ }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment