2013-10-23 2 views
3

아직 작업중인 BATCH 파일을 변환하려고합니다 (질문 : Robocopy | Mirror Destination Including Source Parent Folder).Robocopy 배치를 VB 스크립트로 변환

나는 약간의 진전을 보였습니다. VB로 옮긴 이유는 대화 상자를 추가하여 사용자가 백업 할 폴더를 찾도록 요청하는 것과 같은 것입니다 ...

현재 코드는 현재 원본 (.bat 파일에서 부분적으로 만 변환 됨)입니다.

Dim Command1 

Set objShell = CreateObject("Shell.Application") 
Set objFolder = objShell.BrowseForFolder(0, "Example", 1, "c:\Programs") 
If objFolder Is Nothing Then 
    Wscript.Quit 
End If 
wscript.Echo "folder: " & objFolder.title & " Path: " & objFolder.self.path 

sCmd = "%windir%\System32\Robocopy.exe " 
sDate = Day(Now) & "-" & Month(Now) & "-" & Year(Now) 
sTime = Hour(Now) & "-" & Minute(Now) & "-" & Second(Now) 
sSource = objFolder & " " 
sDestination = "Backups\"& Year(Now) &"\"& Month(Now) &"\"& Day(Now) &"\ " 
sLogDir = "Backups\Logs\"& Year(Now) &"\"& Month(Now) &"\"& Day(Now) &"\ " 
sSwitches = "/SEC /E /Log:"& sTime &".txt" 

Set objShell = CreateObject("Wscript.Shell") 
objShell.Run(sCmd & sSource & sDestination & sSwitches) 

내 문제는 로그 파일에 따라 발생하는 문제입니다.

Source = G:\test\delete\ 
Dest = G:\test\Backups\2013\10\23\ 

한편, 실제 출처는 다음과 같습니다. 소스에의 .VBS가에서 실행되고있는 폴더 : 그것은 "\ 테스트 G"를 부착하는 이유

C:\Users\User\Desktop\delete 

그래서 내가 알아 내기 위해 노력하고 싶은 것입니다.

모두 내 목표는 Robocopy 복사 파일을 가지고 있지만 소스는 사용자 입력 (따라서 폴더 옵션 선택)을 기반으로합니다. 또한 백업 할 위치를 지정하는 "대상"옵션을 추가하고 싶습니다.하지만이 옵션은 실제로 선택 사항입니다.이 첫 번째 문제를 정렬하면 알 수 있습니다.

미리 도움을 청하십시오! 그것은 당신에게 시간을 절약 잘 경우

+2

아마도'sSource = objFolder.self.Path & ""' –

+1

고맙습니다. 당신은 스타입니다 !!! 그러나 공간이없는 폴더로만 작업하는 것 같습니다 : "(큰 그림이나 그와 비슷한 공백이있는 폴더 이름이 있다면 아무 것도하지 않습니다.) – Deadmano

+2

죄송합니다. sSource = Chr (34) & objFolder.self.Path & Chr (34) & ""'.소스에 공백이 포함되어 있으면 robocopy를 호출 할 때 경로를 묶기 위해 따옴표가 필요합니다. –

답변

1

...

ROBOCOPY GUI가 존재한다.

http://technet.microsoft.com/en-us/magazine/2006.11.utilityspotlight.aspx

이 VB 스크립트의 간단한 활용이다.

폴더 선택을 요청하는 메시지가 표시됩니다. VBScript to open a dialog to select a filepath

일단이 링크에서 다른 사용자가 권장하는 코드를 사용하는 방법을 알게되면 내 광기에 대한 간단한 소개 ... 저장할 폴더를 묻고 입력이라는 일괄 처리에 침을 뱉어 백업을 저장할 위치를 다시 묻습니다. 그런 다음 해당 배치 파일을 다음과 같이 호출하십시오.

Call input.bat 

RoboCopy 줄 앞에.

그래서 VB 코드를 활용하는 방법을 결정할 수 있습니다.

'Open Windows Shell Script object 
    Set wShell=CreateObject("WScript.Shell") 
'Executes the MS HTML Application exe to leverage capabilities to select a file. 
    Set iExec=wShell.Exec("mshta.exe ""about:<input type=file id=FILE><script>FILE.click();new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).WriteLine(FILE.value);close();resizeTo(0,0);</script>""") 
'Sets First Prompt for source reference 
    srcepath = iExec.StdOut.ReadLine 
    Set oExec=wShell.Exec("mshta.exe ""about:<input type=file id=FILE><script>FILE.click();new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).WriteLine(FILE.value);close();resizeTo(0,0);</script>""") 
'Sets Second Prompt for destination reference 
    destpath = oExec.StdOut.ReadLine 
    Set wShell=Nothing 

prompt에서 input.bat를 저장하기위한 간단한 VBS 조정.

'This will open the new bat file as txt and write. 
    const forwriting = 2 
    set fso = CreateObject("Scripting.FileSystemObject") 
    set output = fso.OpenTextFile("input.bat", ForWriting, True) 
    output.writeline "set srcepath=" & srcepath 
    output.writeline "set destpath=" & destpath 

따라서 배치를 변환하는 대신 사용 가능한 도구를 활용하고 비용 효율적으로 사용하십시오.