-1

I need to check and return files that exist in the filesystem, but are not listed in a given text file. For instance, my text file (sample.txt) will contain paths like:

\\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

It happens that there are VB project files that exists on the drive but are not among the list, which i want to return along with their full path. For instance:

\\SharedDrive\Data\DevS\Common\app_name\subfolder2\Windows\SharedArchive.vbproj
\\SharedDrive\Data\DevS\NotCommon\app_name2\subfolder1\user2\WebApp2.vbproj

I tried this:

$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

but this does the other way around.

4

1 回答 1

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
于 2013-04-09T12:38:39.183 回答