2013-02-12 2 views
2

DB에 많은 파일 경로가 저장되어 있습니다. 파일이 실제로 존재하는지 확인해야합니다. 나는 전에 이것을했지만 스크립트를 잃어 버렸고 도움이 필요하다.파일이없는 경우 powershell 파일로의 로그 문자열

텍스트 파일에 모든 경로를 넣은 다음 반복하여 루프가 있는지 확인합니다. 존재하지 않으면, 존재하지 않는 경로를 로그 파일에 넣고 싶습니다. 이 같은

뭔가 :

# ! equals -not 

$log = "e:\pshell\notExists.log" 
$log | out-file $log 

$list = Get-Content "e:\pshell\files.txt" 

Foreach ($file in $list) 
{ 
    CHECK IF FILE EXISTS 
    IF IT DOESNT then Write-Output $file 
} 

약간의 도움이?

답변

4

시험 경로? 당신이 inputfile의 한 줄에 하나의 파일 경로 인 경우

$log = "e:\pshell\notExists.log" $log | out-file $log 

$list = Get-Content "e:\pshell\files.txt" 

Foreach ($file in $list) 
{ 
    If (!(test-path $file)) 
    { 
     Write-Output $file 
    } 
} 
0
$log = "e:\pshell\notExists.log" 

Get-Content "e:\pshell\files.txt" | 
where {!(test-path $_)} | 
add-content $log 
2

, 시도 :

$log = "e:\pshell\notExists.log" 

Get-Content "e:\pshell\files.txt" | Where-Object { 
    #Keep only paths that does not exists 
    !(Test-Path $_) 
} | Set-Content $log 
관련 문제