2016-06-19 4 views
3

나는 powershell에서 아래 코드를 사용하여 shortpath를 얻으려고합니다. 일부 폴더의 경우 작동합니다. 일부에서는 작동하지 않습니다.powershell을 사용하여 shortpath 가져 오기

$a = New-Object -ComObject Scripting.FileSystemObject 
$f = $a.GetFile("C:\Program Files\Internet Explorer\iexplore.exe") 
$f.ShortPath 
$f = $a.GetFolder("C:\Program Files\Internet Explorer") 
$f.ShortPath 

OUTP :

Exception calling "GetFile" with "1" argument(s): "Exception from HRESULT: 0x800A0035 (CTL_E_FILENOTFOUND)" 
At C:\Misc\GetShortPath.ps1:4 char:1 
+ $f = $a.GetFile("C:\Program Files\Internet Explorer") 
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : NotSpecified: (:) [], MethodInvocationException 
    + FullyQualifiedErrorId : ComMethodTargetInvocation 

사람이

답변

6

파일폴더를 구별 도와주세요 수 : 폴더를 사용할 수 있지만

$a = New-Object -ComObject Scripting.FileSystemObject 
$f = $a.GetFile("C:\Program Files\Internet Explorer") 
$f.ShortPath 

나는 아래의 오류 유창 :

C:\PROGRA~1\INTERN~1\iexplore.exe 
C:\PROGRA~1\INTERN~1 
+0

고맙습니다. JosefZ. 그것은 내 측면에서 폴더를 검색 할 때 GetFile을 사용하는 어리석은 실수였습니다. – user3180704

관련 문제