title: custom sorting in powershell
body: <p>I have filenames in following format: </p>
  
  <pre><code>[ignore-prefix]-[important-middle]-[ignore-suffix]-[name-with-digits]
  </code></pre>
  
  <p>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).</p>
  
  <p>so my first attempt, naturally:</p>
  
  <pre><code> filelist | Sort-Object -property @{Expression=`
         {$_.FullName.SubString($_.FullName.IndexOf("-")+1)}}
  </code></pre>
  
  <p>This has a problem that the suffix affects order (ignore-aaa-1ignore-wname) is sorted before ignore-aaa-2ignore-aname), so:</p>
  
  <pre><code> $filelist | Sort-Object -property @{Expression=`
         {$_.FullName.SubString($_.FullName.IndexOf("-")+1,`
          $_.FullName.SubString($_.FullName.IndexOf("-")+1).IndexOf("-"))}}
  </code></pre>
  
  <p>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?</p>