2012-11-14 40 views
0

我的腳本正在與當前數組值一起正常工作;但是,實際文件名的前綴中會包含大約五個字符,我想忽略它們:其中一個文件名的示例:03_R_ __1087010076_9999992_35_401_01_20121107_134029_0667.I00.asd。我想分析的文件名的唯一部分是「108701 ####」,忽略前綴03_R___PowerShell - 在搜索數組時使用-pattern

$source ="\\127.0.0.1\baunhof\*" 
[email protected]("108701") 
[email protected]("108702") 
[email protected]("109401", "1094080", "1094090") 
[email protected]("109402", "1094091", "1094082", "1094092") 

$File_Array_8HP70_start = $File_Array_8HP70 | % {$_+"*"} 
$File_Array_8HP70X_start = $File_Array_8HP70X | % {$_+"*"} 
$File_Array_9HP48_start = $File_Array_9HP48 | % {$_+"*"} 
$File_Array_9HP48X_start = $File_Array_9HP48X | % {$_+"*"} 

$files = get-childitem $source -include $File_Array_8HP70_start -recurse 
$files1 = get-childitem $source -include $File_Array_8HP70X_start -recurse 
$files2 = get-childitem $source -include $File_Array_9HP48_start -recurse   

回答

2

可以忽略前N個字符,通過手動過濾:

get-childitem $source -recurse | where { $_.Name -like "???????108701*" } 

如果你想通過圖案陣列這種方式來列舉,這裏是你如何能做到這一點:

get-childitem $source -recurse | foreach { 
    foreach($pattern in $likes) { 
    if($_.Name -like $pattern) { 
     $_ 
     break; 
    } 
    } 
}