首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在VBScript中使用xcopy

在VBScript中使用xcopy
EN

Stack Overflow用户
提问于 2009-12-25 11:48:54
回答 1查看 10.3K关注 0票数 0

这是我之前问题的后续(Copy Update Create VBScriptFile Folder copy)。到目前为止,我有以下脚本可以使用xcopy复制文件

代码语言:javascript
复制
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set wshShell = WScript.CreateObject("WScript.Shell")
strUserName = wshShell.ExpandEnvironmentStrings("%USERNAME%")

' Discover Current Drive Path
curDrv = objFSO.GetParentFolderName(WScript.ScriptFullName) 'Drive Path
' USB Drive  and folder Path
upath = curdrv & "\ACG" 

' Source
avg8 = "c:\Docume~1\alluse~1\applic~1\avg8\update\download\*.*"
avg9 = "c:\Docume~1\alluse~1\applic~1\avg9\update\download\*.*"

If struserName = DARIO Then 
  '(1) GOTO Update
End If

If Not objFSO.FolderExists (upath) Then
  objFSO.CreateFolder (upath)
End If

If objFSO.FolderExists (avg9) Then
  'WshShell.Run "xcopy c:\Docume~1\alluse~1\applic~1\avg9\update\download\*.* usbdrive:\acg /D", , True
  '(2) WshShell.Run "xcopy avg9 upath /D", , True
  WshShell.Run "xcopy " & avg9 & " " & upath & " /D", , True
End If

If objFSO.FolderExists (avg8) Then
  'WshShell.Run "xcopy c:\Docume~1\alluse~1\applic~1\avg8\update\download\*.* &    usbdrive:\acg & /D", , True
  '(3) WshShell.Run "xcopy avg8 upath /D", , True
  WshShell.Run "xcopy " & avg8 & " " & upath & " /D", , True
End if

MsgBox "Definition Files Copied to your USB Drive @ " & upath, vbInformation, "Copy   Success..."
WScript.Quit

' Update 
If Not objFSO.FolderExists("C:\Updates") Then
  objFSO.CreateFolder "C:\Updates"
End If

If objFSO.FolderExists (upath) then
  Wshshell.Run "xcopy " & upath  & " " & "C:\Updates /D", , True '(4)
  MsgBox "Update Files Copied to C:\Updates" , vbInformation, "Copy Destination"
End IF

' Process
Message = "Click OK to Start Updating product." & vbCr & vbCr
Message = Message & "Click Cancel or (Esc) to Exit." &vbCr & vbCr
Message = Message & "Keep Selecting OK until you get" & vbCr
Message = Message & "the Message :-" & vbCr & vbCr
Message = Message & "''No New Update Files Available''" & vbCR & vbCR
X = MsgBox(Message, vbOKCancel, "AVG Update Module")

Select Case X
  Case vbCancel 
    MsgBox (strUserName & " cancelled the process.") , vbCritical, "Operation Terminated."
    Wscript.Quit

  Case vbOK
    If objFSO.FileExists("C:\Program Files\AVG\AVG89\avgupd.exe") Then
      WshShell.Run "C:\Program Files\AVG\AVG9\avgupd.exe" /source=folder /path="C:\Updates"
    End If

    If objFSO.FileExists("C:\Program Files\AVG\AVG8\avgupd.exe") Then
      WshShell.Run "C:\Program Files\AVG\AVG8\avgupd.exe" /source=folder /path="C:\Updates"
      '(5) Loop to Process
    End If
End Select

不幸的是,xcopy没有发生。有人能解释我的剧本出了什么问题,并指出了实现点(1) - (5)的正确方向吗?谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2009-12-28 13:52:26

使用FileSystemObject.CopyFile代替xcopy,就像这样。

代码语言:javascript
复制
If objFSO.FolderExists (avg9) Then
  objFSO.CopyFile "c:\Docume~1\alluse~1\applic~1\avg9\update\download\*.*", "usbdrive:\acg", True
End If

也可以使用If而不是GOTO

代码语言:javascript
复制
If struserName = "DARIO" Then
    'Do whatever should be done if the user is DARIO
Else
    'Do whatever should be done if the user is not DARIO
End If

您还可以使用这样的子例程或函数

代码语言:javascript
复制
if struserName = "DARIO" Then
    DoDARIOStuff
else
   DoOtherStuff
end if

然后定义代码中其他地方的子程序,如下所示

代码语言:javascript
复制
Sub DoDARIOStuff
    'Do whatever should be done if the user is DARIO
End Sub

Sub DoOtherStuff
    'Do whatever should be done if the user is not DARIO
End Sub
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1961044

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档