I have filenames in following format:
[ignore-prefix]-[important-middle]-[ignore-suffix]-[name-with-digits]
I need to sort according to following rules: first by middle part, then by name, in natural order (i.e. foobar10 > foobar2). I don't know prefix value, but I know the separator (dash).
so my first attempt, naturally:
filelist | Sort-Object -property @{Expression=`
{$_.FullName.SubString($_.FullName.IndexOf("-")+1)}}
This has a problem that the suffix affects order (ignore-aaa-1ignore-wname) is sorted before ignore-aaa-2ignore-aname), so:
$filelist | Sort-Object -property @{Expression=`
{$_.FullName.SubString($_.FullName.IndexOf("-")+1,`
$_.FullName.SubString($_.FullName.IndexOf("-")+1).IndexOf("-"))}}
Ok, that sorts by the middle but already unwhieldy. If I'm to add natural sort that would be even worse. What's more elegant way of doing that?