-1

I need to write a vbscript for Copying files from local directory(Windows) to another(shared drive) and verify the counts at the end to make sure everything copied successfully. Any ideas on what the script will look like?

Here is what I recorded using 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"
vins
  • 15,030
  • 3
  • 36
  • 47
  • What have you got so far? – 404 Feb 01 '15 at 08:36
  • Here is what I recorded using 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" – Oleg Mikhalitsyn Feb 01 '15 at 20:05
  • 1
    You can (and should) update your question by editing it instead of adding comments. – TheBlastOne Feb 04 '15 at 10:08

1 Answers1

3

To copy files from one foler to another, Why do you record using QTP/UFT? The script recorded by QTP will not be reliable. (might not work everytime.) QTP supports VBScript. It is easy to copy files from one folder to another folder using VBScript.

To copy all files from temp1 to temp2 folder - just these 2 lines will do

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

Once files are moved, You want to compare the files count. (I assume temp2 folder was empty before copying the files)

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
vins
  • 15,030
  • 3
  • 36
  • 47