mlhaufe

Extended dir Pattern

Jun 7th, 2011
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Function Rec($path){
  2.     if($path[-1] -eq '/' -or $path[-1] -eq '\'){
  3.         $path += '**'
  4.     }
  5.     $rec = $path -split '**', 0, 'simplematch'
  6.     if($rec.length -gt 1){ #recursive
  7.         dir -r $rec[0] | ?{ !($_.PSIsContainer) -and ($_.FullName -like ($rec -join '*')) } | %{ $_.FullName }
  8.     } else { #non-recursive
  9.         dir $rec[0] | ?{ !$_.PSIsContainer } | %{ $_.FullName }
  10.     }
  11. }
  12.  
  13. Rec("C:\test\**\sub2\*.sml")
  14. #C:\test\sub0\sub3\sub2\set.sml
  15. #C:\test\sub0\sub3\sub2\vector3.sml
  16. #C:\test\sub1\sub2\set.sml
  17. #C:\test\sub1\sub2\vector3.sml
Advertisement
Add Comment
Please, Sign In to add comment