Vbscript 在VBS中使用xcopy(带扭曲)

Vbscript 在VBS中使用xcopy(带扭曲),vbscript,xcopy,folderbrowserdialog,Vbscript,Xcopy,Folderbrowserdialog,好的,这里有一个交易:我正在尝试组合一个脚本来执行一个简单的xcopy。问题是我希望用户能够浏览源文件夹和目标文件夹。我有几个简单的部分,但我无法将它们组合在一起,特别是试图区分源代码和目标代码,并试图从浏览功能获得输出 Set objShell = CreateObject("Shell.Application") Set objFolder = objShell.BrowseForFolder(0, "Example", 1, "c:\Programs") Set objShell = C

好的,这里有一个交易:我正在尝试组合一个脚本来执行一个简单的xcopy。问题是我希望用户能够浏览源文件夹和目标文件夹。我有几个简单的部分,但我无法将它们组合在一起,特别是试图区分源代码和目标代码,并试图从浏览功能获得输出

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder(0, "Example", 1, "c:\Programs")

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder(0, "Example", 1, "c:\Programs")

Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "Xcopy ""objShell"" ""objShell"" /C /D /E /H /I /K /R /S /Y"

任何帮助都将不胜感激。

像这样,它可以工作,在Windows 7上测试

Set objShell = CreateObject("Shell.Application")
Set oFso = CreateObject("Scripting.FileSystemObject")
root = "c:\"
Set source = get_path(objShell.BrowseForFolder(0, "Source folder", 1, root))
Set target = get_path(objShell.BrowseForFolder(0, "Target folder", 1, root))
Set objShell = WScript.CreateObject("WScript.Shell")
command = "Xcopy """&source&""" """&target&""" /C /D /E /H /I /K /R /S /Y"
'wscript.echo command
objShell.Run command

function get_path(foldername)
  Set oFolderItem = foldername.Items.Item
  Set selected = oFso.GetFolder(oFolderItem.Path)
  If selected.IsRootFolder Then
    Set get_path = oFso.GetDrive(selected.Drive)
  Else
    Set get_path = oFso.GetFolder(oFolderItem.Path)
  End If
end function

像这样,它将工作,在Windows7上测试

Set objShell = CreateObject("Shell.Application")
Set oFso = CreateObject("Scripting.FileSystemObject")
root = "c:\"
Set source = get_path(objShell.BrowseForFolder(0, "Source folder", 1, root))
Set target = get_path(objShell.BrowseForFolder(0, "Target folder", 1, root))
Set objShell = WScript.CreateObject("WScript.Shell")
command = "Xcopy """&source&""" """&target&""" /C /D /E /H /I /K /R /S /Y"
'wscript.echo command
objShell.Run command

function get_path(foldername)
  Set oFolderItem = foldername.Items.Item
  Set selected = oFso.GetFolder(oFolderItem.Path)
  If selected.IsRootFolder Then
    Set get_path = oFso.GetDrive(selected.Drive)
  Else
    Set get_path = oFso.GetFolder(oFolderItem.Path)
  End If
end function