2013-04-09 3 views
-1

파일 시스템에 존재하지만 주어진 텍스트 파일에 나열되지 않은 파일을 확인하고 반환해야합니다. 예를 들어, 내 텍스트 파일 (의 Sample.txt)는 같은 경로를 포함합니다 :이 드라이브에있는 VB 프로젝트 파일입니다하지만 난과 함께 반환 할 목록 중 아님 일powershell을 사용하여 텍스트 파일에 경로가없는 파일을 찾는 방법

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

그들의 전체 경로. 예를 들어 :

$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 

그러나 이것은 다른 방법으로 주위를 수행합니다

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

이 시도.

+1

음이 ... 아니, 코드는 여러분이 원하는 것을 정확히 않습니다. 하지만,'Test-Path $ _'를'Test-Path -LiteralPath $ _'로 변경하는 것이 안전 할 수 있습니다. –

+0

@AnsgarWiechers :이 코드는 실제로 목록에 있지만 드라이브에 존재하지 않는 파일을 반환합니다. 하지만 다른 방법을 원합니다 - 목록에는 없지만 드라이브에있는 파일. –

답변

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 
+0

코드는 기본 디렉토리 아래의 모든 폴더를 반환합니다. 나는 그 목록에없는 vb 프로젝트 파일 이름 (sample.txt) 만 리턴하고 드라이브에있다. –

+0

업데이트 된 답변보기 –