by link12 at 2012-11-05 08:09:16
I’m trying to use the code below to end up with only the "ddd" in the name and not "aaa-bbb-ccc-". I’m looking at a bunch of files in a directory with the same format that I would likeby link12 at 2012-11-05 10:07:41
to trim/split to only the end.
File Format
aaa-bbb-ccc-ddd
aaa-bbb-ccc-ddd
aaa-bbb-ccc-ddd
$a = get-childitem c:\testing | foreach-object {$.BaseName} | Out-String
foreach ($i in $a){
$i.split(‘-’)[3]
}
In my output I get the first "ddd" but I also get "aaa"
I figured it out. I removed the " | out-string"by RichardSiddaway at 2012-11-05 10:14:06
works great now.
This should do what you want
Get-ChildItem -Path c:\testf | foreach { ($.BaseName -split "-")[3] }