0

My script is working properly with the current array values; however, the actual file names will have about five characters in the prefix that I would like ignored: Example of one of the file names: 03_R___1087010076_9999992_35_401_01_20121107_134029_0667.I00.asd . The only part of the file name that I would like to parse is "108701####" ignoring the prefix 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          

1 Answer 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;
    }
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.