2015-02-05 2 views
1

WinRAR이 실행되고 일종의 작업을 수행하는 것처럼 보이지만 찾을 수없는 것처럼 보이는 특정 위치에서 지정된 디렉터리를 압축해야하는 Powershell 스크립트가 있습니다. 여기서 zip 파일은 파일 시스템에서 끝납니다.Powershell 명령 줄 Winrar가 예상 위치에 파일을 만들지 않습니다.

아이디어는 내가 디렉토리를 압축 한 다음 파일 시스템에서 압축 해제 된 디렉토리를 삭제한다는 것입니다.

$ 파일 경로 변수는 디렉토리의 위치를 ​​압축 (기본 위치 포함)로되면, $ rarExePath는 WinRAR.exe

# zips up any files in the directory 
function ZipDirectory($filePath, $rarExePath) 
{ 
    "Zipping directory $filePath" 

    #$zipFilePath = (Split-Path $filePath -Parent) 

    $archiveName = (Split-Path $filePath -Leaf) + ".rar" 

    "Zipping directory $dirPath to file $archiveName $zipFilePath" 

    Start-Process $rarExePath -ArgumentList "a -r $archiveName $filePath" 

    #Remove-Item -Recurse $filePath 

    "Completed..." 
} 

의 경로에 분명히 잘못이 있나요이다 내 명령?

답변

2

는 추가하여 스크립트가 실행되는 경우에있어 어떤 디렉토리를 찾기 :

resolve-path . 

스크립트에.

WinRAR은 현재 파일을 현재 디렉토리에 저장하고 있으며 그 파일이 무엇인지 모를 가능성이 있습니다.

내가 만든 파일 원하는 명시 적 경로 추가 $archiveName 변수를 변경 할 것 : 당신이 올바른, 그것은 PowerShell 스크립트가있는 디렉토리에 파일을 출력하고 있습니다 네

PS C:\Users\pax> $x = 'c:\desired\' + (split-path "c:\a\b\xyzzy" -leaf) 

PS C:\Users\pax> $x 
C:\desired\xyzzy 
+0

을 ...에서 –