转换的Robocopy一批VB脚本 [英] Converting Robocopy Batch To VB Script

查看:309
本文介绍了转换的Robocopy一批VB脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想转换为<一个批处理文件,我仍然工作在(问题href=\"http://stackoverflow.com/questions/19519371/robocopy-mirror-destination-including-source-parent-folder\">Robocopy |。镜像目的包括源父文件夹)

我已经取得了一些进展,我搬到了VB的原因是添加更多的功能,如添加一个对话框,要求用户浏览文件夹,他们想备份...

I've made some progress, and the reason I moved to VB is to add a bit more functionality, like adding a dialog box to ask the user to browse for a folder they'd like to backup...

现在的code我目前有(只是部分从我原来的.bat文件转换);

Now the code I currently have (only partially converted from my original .bat file);

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)

我的问题是,这是根据该日志文件发生什么;

My issue is that this is what happens according to the log file;

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

同时,真正源泉是;

Meanwhile the true source is;

C:\Users\User\Desktop\delete

所以,想什么,我要揣摩就是为什么它被贴上G:\\测试,该.vbs正在从运行的文件夹,其源

So what I'd like to try to figure out is why it is affixing "G:\test", the folder the .vbs is being run from, to its source.

所有的一切,我的目标是只复制的Robocopy文件,但来源是基于用户输入(因此选择一个文件夹选项)。我也想备份添加一个目标选项,您指定在哪里......但是,这确实是可选的,我相信我能明白这一点,如果我得到这个第一个问题来分类的。

All in all, my goal is to just have Robocopy copy files, but the source is based on user input (hence the select a folder option). I would also like to add a "destination" option, that you specify where to backup to... But that is really optional, I'm sure I can figure that out if I get this first issue sorted.

先感谢您的任何和所有帮助!

Thanks in advance for any and all assistance!

推荐答案

那么,如果这样可以节省你任何时候...

Well if it saves you any time...

ROBOCOPY GUI存在。

RoboCopy GUI exists.

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

这是VB脚本的一个简单的利用率。

This is a simple utilization of VB Script.

有关提示文件夹选择用户看到这一点。
<一href=\"http://stackoverflow.com/questions/21559775/vbscript-to-open-a-dialog-to-select-a-filepath\">VBScript打开一个对话框,选择文件路径

See this for prompting the user for folder selection. VBScript to open a dialog to select a filepath

一旦你如何使用这个链接上的其他用户推荐code中的JIST。一个简短的介绍到我的疯狂......提示您要保存,并吐出了一个叫输入批处理,然后再次提示在哪里保存备份的文件夹。然后调用批处理文件是这样的:

Once you get the jist of how to use the code recommended by the other user on this link. A brief intro to my madness... Prompt the folder you wish to save and spit it out to a batch called Input then prompt again where to save the backup. Then call that batch file like this:

Call input.bat

您的Robocopy行之前。

Before your RoboCopy lines.

因此​​让我们决定如何利用VB code。

So lets determine how to leverage the vb code.

'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

VBS简单的调整从提示保存input.bat。

Simple VBS adjustments to save the input.bat from the prompting.

'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

因此​​,而不是转换您的批处理,利用你拥有可用的工具,并实现低成本高效益为你的努力。

So instead of converting your batch, leverage the tools you have available and make it cost effective for your effort.

这篇关于转换的Robocopy一批VB脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆