我需要检查并返回文件系统中存在的文件,但不会列在给定的文本文件中。例如,我的文本文件(sample.txt)将包含如下路径:
\\SharedDrive\Data\DevS\Common\app_name\subfolder1\Archive\Archive1.vbproj
\\SharedDrive\Data\DevS\NotCommon\app_name\subfolder1\user\WebApp.vbproj
\\SharedDrive\Data\DevS\UnCommon\app_name\subfolder1\Manager\Managerial.vbproj
有些VB项目文件存在于驱动器上,但不在列表中,我想要返回它们的完整路径。例如:
\\SharedDrive\Data\DevS\Common\app_name\subfolder2\Windows\SharedArchive.vbproj
\\SharedDrive\Data\DevS\NotCommon\app_name2\subfolder1\user2\WebApp2.vbproj
我试过了:
$log = "e:\pshell\notExists.log"
Get-Content "e:\pshell\Sample.txt" | Where-Object {
#Keep only paths that does not exists
!(Test-Path $_)
} | Set-Content $log
但这反过来。
答案 0 :(得分:0)
试试这个:
$baseDir = "\\SharedDrive\Data\DevS"
$log = "..."
$paths = Get-Content sample.txt
Get-ChildItem $baseDir -Recurse -Filter *.vbproj | ? {
-not $_.PSIsContainer -and $paths -notcontains $_.FullName
} | % { $_.FullName } | Set-Content $log