0

我的脚本与当前数组值正常工作;但是,实际文件名的前缀中大约有五个我想忽略的字符:文件名之一的示例: 03_R_ __1087010076_9999992_35_401_01_20121107_134029_0667.I00.asd 。我要解析的文件名的唯一部分是 "108701####" 忽略前缀 03_R___

$source ="\\127.0.0.1\baunhof\*"
$File_Array_8HP70=@("108701") 
$File_Array_8HP70X=@("108702")
$File_Array_9HP48=@("109401", "1094080", "1094090")
$File_Array_9HP48X=@("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          
4

1 回答 1

2

You can ignore first N characters, by filtering manually:

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

If you want to enumerate through an array of patterns this way, here is how you can do it:

get-childitem $source -recurse | foreach {
  foreach($pattern in $likes) {
    if($_.Name -like $pattern) {
      $_
      break;
    }
  }
}
于 2012-11-15T20:05:46.880 回答