Advertisement
Guest User

powershell month abbreviation to month number in a filename

a guest
Sep 12th, 2017
442
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $AbrevMonthNames = (Get-Culture).DateTimeFormat.AbbreviatedMonthNames
  2.  
  3. $InStuff = get-item *.csv
  4. # grab 3rd from last & then 2nd item of each .Split()
  5. $MonthAbr = $InStuff.name.Split('_')[-2].Split('-')[1]
  6.  
  7. # correct for off-by-one
  8. $MonthNum = '{0:00}' -f ($AbrevMonthNames.IndexOf($MonthAbr) + 1)
  9.  
  10. # replace the abbreviated month with the month number
  11. $outstuff = $instuff.name -replace $monthabr,$monthnum
  12.  
  13. # rename the original file with the new name
  14. rename-item $instuff $outstuff
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement