搜索匹配项 PowerShell "-icontain" & "ilike"



如果一个目录中的对象包含在我的过滤器中,我会尝试过滤它们。我遇到了一个问题,我不想过滤的文件的名称中也包含我的文件。

我要筛选的文件如下:0000.pdf0001.tsv0065.png语法是一样的,我要过滤的每个项目都以"开头;00〃;,包含一个点,并且在该点之后有树字符,如";png"tif";或";doc";

我不想筛选的文件如下:batman_N_#_0000.xlsspiderman_N_#_0022.xlsbane_N_#_0020.png

我的代码看起来像:

if($foldercontentz -ilike "00*.*"){
Add-Content -path $destinationFolderSave___missingFiles.txt -value $folderDirection 
}

有没有更好的方法来过滤它,或者我可以用另一种方法过滤这些文件,这可能吗?或者让我更改文件。我认为它会过滤文件,因为我的对象以"开头;00";每次,我不想过滤的文件没有。

编辑:

$pdfFiles = "DesktopImportsuperheros"
$sidepaths = Get-ChildItem -path $pdfFiles -Directory
$filesfolder = New-Object System.Collections.Generic.List[System.Object]
for ($i = 0; $i -le $sidepaths.count; $i++) {
$filesfolder.add($sidepaths[$i])
}
for ($i = 0; $i -le $filesfolder.count; $i++) {
$folder = $pdfFiles + $filesfolder[$i]
#write-host $folder
$folder | foreach {
$contentfolder = Get-ChildItem $_
$location = $directories[$i]
if ($contentfolder -contains "00*.*" ) {
#Write-Output $contentfolder "haaadadasd" $filesfolder[$i]
Add-Content -path $pdfFiles___missingFiles.txt -value $contentfolder
}

# ...
}
# ...
}

你在找这样的东西吗?

$rootFolder = 'X:DesktopImportsuperheros'             # path to the superheros folder
$outFile    = 'X:DesktopImport___missingFiles.txt'   # full path and filename for the output file
# look for Files with a name beginning with '00' and write their full path and name to the output file.
(Get-ChildItem -Path $rootFolder -File -Filter '00*.*' -Recurse).FullName | Add-Content -Path $outFile

最新更新