QTP:如何从一个位置复制文件并将其粘贴到另一个位置并在最后验证文件数

QTP: How to copy file from onle location and paste it into another and verify file count at the end

我需要编写一个 vbscript 用于将文件从本地目录 (Windows) 复制到另一个(共享驱动器)并在最后验证计数以确保所有内容都已成功复制。关于脚本的外观有什么想法吗?

这是我使用 GUI UFT 录制的内容:

SystemUtil.Run "C:\Users\Downloads" 
Window("Documents").WinObject("Items View").WinList("Items View").Activate "Unified Functional Testing" 
Window("Documents").WinObject("Items View").WinList("Items View").Select "APITest1" 
Window("Documents").WinObject("ShellView").WinMenu("ContextMenu").Select "Copy" 
Window("Documents").Restore Window("Documents").WinTreeView("WinTreeView").Select "Desktop;This PC;Downloads" 
Window("Documents").WinObject("ShellView").WinMenu("ContextMenu").Select "Paste"

要将文件从一个文件夹复制到另一个文件夹,为什么要使用 QTP/UFT 进行录制? QTP 录制的脚本将不可靠。 (可能不是每次都有效。)QTP 支持 VBScript。使用 VBScript 可以轻松地将文件从一个文件夹复制到另一个文件夹。

将所有文件从 temp1 复制到 temp2 文件夹 - 只需这两行即可

Set oFSO = CreateObject("Scripting.FileSystemObject") 
oFSO.CopyFile "C:\vIns\temp1\*.*" , "C:\vIns\temp2\" , TRUE

移动文件后,您想比较文件数。 (我假设 temp2 文件夹在复制文件之前是空的)

iTemp1Count = oFSO.getFolder("C:\vIns\temp1\").Files.Count
iTemp2Count = oFSO.getFolder("C:\vIns\temp2\").Files.Count

If iTemp1Count = iTemp2Count Then
     Msgbox "all files are copied"
Else
     Msgbox "Something is wrong!!!"
End If