2017-01-12 3 views
1

다른 디렉토리에 압축 파일 묶음 (.ARJ)을 자동으로 추출하려고합니다. _Work_Splunk_TestBed \ Branch00 \ LOAN.ARJ : D - 압축 파일 (ARJFileNames.txt) 샘플의텍스트 파일에서로드 된 문자열을 사용하여 외부 명령 실행

  1. 현재 위치와 이름 :

    나는 현재 정보의 2 비트를 저장하기 위해이 개 텍스트 파일을 사용하고 있습니다

  2. 파일이 (ARJFileLocations.txt) 샘플을 추출하기위한 대상 위치 - D : _Work_Splunk_TestBed \ Branch00

나는 W를 실행하는 WScript.Shell 명령을 사용하려고 inRAR을 사용하여 현재 위치에서 대상 위치로 파일을 추출합니다.

내 문제는 루프에서 외부 명령을 호출 할 때 텍스트 파일에서 끌어 오기 문자열을 첨부 할 수없는 것처럼 보입니다. 실제로 WinRar 및 해당 스위치에 대한 호출과 함께 사용합니다. 명령.

'Declaring Constants 
Const ForReading = 1, ForWriting = 2, ForAppending = 3 
'Declaring Variables 
Dim fso, strFilePath, strFileName, fFilePath, fFileName, objShell, WinRAR, strCMD, SevenZip, ARJ 

Set fso = CreateObject("Scripting.FileSystemObject") 
Set objShell = WScript.CreateObject ("WScript.shell")  

'Open Text Files for use 
Set strFilePath  = fso.OpenTextFile("D:\_Work\_Splunk\_TestBed\ARJFileLocations.txt", ForReading, TristateFalse) 
Set strFileName = fso.OpenTextFile("D:\_Work\_Splunk\_TestBed\ARJFileNames.txt", ForReading, TristateFalse) 


Do Until strFilePath.AtEndOfStream 
    fFilePath = strFilePath.ReadLine 'Get the location of the ARJ file 
    fFileName = strFileName.ReadLine 'Get the target location for ARJ file contents 
    'Storing the command as 1 string' 
    strCMD = "winrar x -y " & " " & fFileName & " " & fFilePath 
    'Running the command in CLI' 
    objShell.Run strCMD 
Loop 

'Cleaning Up 
Set strFilePath = Nothing 
Set strFileName = Nothing 
Set objShl = Nothing 

답변

1

Read Concatenation Operator (&) 참조 :

여기에 내 현재 코드입니다. 이처럼 명령 프롬프트를 입력 한 경우

명령 줄이 궁극적으로 나타납니다 (Wscript.Echo Command에 의해 확인) :

Command = """" & WinRAR & "\WinRAR.exe"" X " & fDLocation & " " & fTLocation 
'   ↑↑↑↑      ↑↑ 
' results to 
' "D:\Program Files\WinRAR\WinRAR.exe" X ARJLocation TargetLocation 
' ↑         ↑ 

사용하여 다음 fDLocation 또는 fTLocation에 공백이 또한

Command = """" & WinRAR & "\WinRAR.exe"" X """ & fDLocation & """ """ & fTLocation & """" 
'           ↑↑     ↑↑ ↑↑     ↑↑↑↑ 
' results to 
' "D:\Program Files\WinRAR\WinRAR.exe" X "ARJ Location" "Target Location" 
' ↑         ↑ ↑   ↑ ↑    ↑ 

가 포함 된 경우 , 다음과 같이 스크립트와 WinRAR.exe 프로그램을 동 기적으로 실행하는 것을 고려해보십시오 (참조 Run Method (Windows Script Host) 기사 참조) :

Dim intRunResult 
Do Until strARJLocations.AtEndOfStream 
    fDLocation = strARJLocations.ReadLine  'Get the location of the ARJ file' 
    fTLocation = strTargetLocation.ReadLine 'Get the target location for ARJ file contents' 
    Command = """" & WinRAR & "\WinRAR.exe"" X """ & fDLocation & """ """ & fTLocation & """" 
    intRunResult = objShell.Run (Command, 1, True) 
Loop