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

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
ashish g
  • 281
  • 3
  • 7
  • 14
  • 1
    Umm... no, your code does exactly what you said you want it to do. You may want to change `Test-Path $_` into `Test-Path -LiteralPath $_`, though, just to be on the safe side. – Ansgar Wiechers Apr 09 '13 at 09:10
  • @AnsgarWiechers: This code actually returns the files which are part of the list but do not exist on the drive. But I want the other way around - The files that are not there in the list but exist on the drive. – ashish g Apr 09 '13 at 11:48

1 Answers1

0

Try this:

$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
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
  • The code returns all the folders under the base directory. I want to return only the vb project file names that are not there in the list (sample.txt) and are there on the drive. – ashish g Apr 10 '13 at 04:44