Forum Discussion
MrSnowman2010
Aug 17, 2021Copper Contributor
Help With Filename Comparisons and Output
Hi all, I'm looking for some help if possible. Please bear in mind I am a complete Powershell novice so feel free to dumb things down as appropriate. Also apologies if this is in the wrong sectio...
Jonathan_Allen
Jan 31, 2022Brass Contributor
It would be better to pattern match to remove leading 0's than fix the filename length to 5 chars.
#Set up
# create test directory
new-item c:\temp\hub\demo -itemtype directory
# Move to that directory
sl c:\temp\hub\demo
# create some new files
$null = new-item c:\temp\hub\demo\123.pdf, c:\temp\hub\demo\0234.pdf, c:\temp\hub\demo\00345.pdf, c:\temp\hub\demo\100345.pdf, c:\temp\hub\demo\0034504.pdf
# example
# get all items and then remove leading zeros
get-childitem | split-path -leaf | foreach { $_ -replace '^0*'}