2014-02-15 2 views
0

다른 링크들 사이에 끊어진 링크가 포함될 수있는 폴더의 내용을 모두 삭제해야합니다. 폴더 경로는 변수에 의해 제공됩니다. 문제는 PowerShell이 깨진 링크를 제거하지 못합니다.끊어진 링크 삭제

$folderPath = "C:\folder\" 

시도 1 $folderPath 대신 그 값 그대로 전달되는 때문에

Start-Job { cmd /c rmdir $folderPath } 

실패 2

Remove-Item : Could not find a part of the path 'C:\folder\brokenLink'. 
At line:1 char:1 
+ Remove-Item -Force -Recurse -Path $folderPath 
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : WriteError: (C:\folder\brokenLink:String) [Remove-Item], DirectoryNot 
    FoundException 
    + FullyQualifiedErrorId : RemoveItemIOError,Microsoft.PowerShell.Commands.RemoveItemCommand 

시도가

Remove-Item -Force -Recurse -Path $folderPath 

오류와 함께 실패

Start-Job { cmd /c rmdir $folderPath } | select command 

Command                        
-------                        
cmd /c rmdir $folderPath                   

.NET 프레임 워크를 사용하는 것 외에 어떤 제안이 있습니까?

나는 이전에 마운트 된 파티션을 가리키는 폴더로 말하는 겁니다 깨진 링크에 의해 편집
더 이상 존재하지 않습니다. 폴더는 여전히 사용할 수 있지만 그것으로 이동하려고 할 때 대상이 더 이상 존재하지 않기 때문에이 오류가 발생합니다
오류 :

C:\folder\brokenLink refers to a location that is unavailable. It could be on a hard drive on this computer, or on a network. Check to make sure that the disk is properly inserted, or that you are connected to the Internet or your network, and then try again. If it still cannot be located, the information might have been moved to a different location.

+0

당신에 명확하게 할 수있는 작업 "깨진 링크?" 바로 가기 파일로 가득 찬 폴더가 있습니까? –

+0

@TrevorSullivan 나는 내 설명으로 질문을 편집했다. – slybloty

답변

2

이 작동합니다

$folderPath = "C:\folderContaingBrokenSymlinks\"; 
$items = ls $folderPath -Recurse -ea 0; 
foreach($item in $items){ 
    if($item.Attributes.ToString().contains("ReparsePoint")){ 
     cmd /c rmdir $item.PSPath.replace("Microsoft.PowerShell.Core\FileSystem::",""); 
    } 
    else{ 
     rm -Force -Recurse $item; 
    } 
} 
+0

스 니펫을 붙여 넣는 대신 조금 설명 할 수 있습니까? –