UFT File system test - hp-uft

Im a rookie on HP UFT testing and work on a data migration project I would like to automate.
Every day, we get a set of folder and files syncronize from a vendor with a following syncronization report(.csv file).
I would really like to test if the actual .csv file containing a list of files updated in the filesystem exists.
I get the .csv file on a network share, I open it and see a list of files with
data paths, which should be used to (loop)search though the filesystem and check if the files is actually on the location. How do I do that with UFT??

sample script to get all csv content and looping through content and verifying whether files exists or not.
filename = "C:\path\list.csv"
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(filename)
Do Until f.AtEndOfStream
filepath=f.ReadLine 'assuming every line as file full path
if FSO.fileexists(filepath) then
print filepath & " file is avaialble"
' do your checks here
else
print filepath & " file is not avaialble"
End if
Loop
f.Close

Related

FlashAir Execute on Write Event Properties

Using the dropbox sample code I am working on a Lua script that will run each time a new file is added (a photo in this case) to a specific folder. I see examples to iterate through a folders files to upload them each in turn. What I need is the properties that are passed to the file that will execute each time a new file is written. I'm hoping it will be passed the filename for the last file created so I can use that to upload the file directly to Dropbox or FTP site.
HI someone in japan solved your doubt as the following.
last_filepath = ""
max_mod = 0
fpath = "/DCIM/100__TSB"
for filename in lfs.dir(fpath) do
filepath = fpath .. "/" .. filename
mod = lfs.attributes( filepath, "modification" )
if mod > max_mod then
max_mod = mod
last_filepath = filepath
end
end
basically it set a directory to search for the latest file with newest modification date/time.
details r here
http://dotnsf.blog.jp/archives/1040120555.html

Compare two files in two different folders and replace it by the newer

With this VBScript code I was able to copy files. If the file exists it does nothing, if not it will copy the files needed.
Dim Photo
SourceFolder = "C:\Photo1"
DistinationFolder = "C:\Photo2"
Set ObjPhoto = CreateObject("Scripting.FileSystemObject")
For Each Photo In ObjPhoto.GetFolder( SourceFolder).Files
If Not ObjPhoto.FileExists(ObjPhoto.BuildPath(DistinationFolder, Replace(Photo.Name, ".jpg", ".bmp"))) Then
photo.Copy ObjPhoto.BuildPath(DistinationFolder, Photo.Name), True
End If
Next
I want to compare the files if the source files also exists in the destination folder and replace it by the newer.
If you want to overwrite based on the last modified date, then the File object has the property you want: DateLastModified. (You can check all properties of the File object here.)
You already have access to the source file objects (your code's Photo variable) so you just need to get the target's file object.
Something like this should work:
Dim Photo
Dim targetFile, bmpTargetFilename, jpgTargetFilename
SourceFolder = "C:\Photo1"
DistinationFolder = "C:\Photo2"
Set ObjPhoto = CreateObject("Scripting.FileSystemObject")
For Each Photo In ObjPhoto.GetFolder(SourceFolder).Files
bmpTargetFilename = ObjPhoto.BuildPath(DistinationFolder, Replace(Photo.Name, ".jpg", ".bmp"))
jpgTargetFilename = ObjPhoto.BuildPath(DistinationFolder, Photo.Name)
If ObjPhoto.FileExists(bmpTargetFilename) Then
' Get the target file object
Set targetFile = ObjPhoto.GetFile(jpgTargetFilename)
' Now compare the last modified dates of both files
If Photo.DateLastModified > targetFile.DateLastModified Then
Photo.Copy jpgTargetFilename, True
End If
Else
Photo.Copy jpgTargetFilename, True
End If
Next
A couple of notes:
It seems you are checking for the existence of a .BMP file yet copying a .JPG file, so I made it explicit by using two variables.
I am also assuming you want to compare the JPG files, since those are the ones being copied.

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

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"
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

Need to write filenames to a text file

I am very new to VB Scripting and I am looking to see if there is a way to look at a directory get the file names and then write those file names to a text file. I would think that the Path.GetFileName Method would work, but I can't seem to get it to work. Maybe I am using it the wrong way.
Here is a simple script that will echo the filenames in the "C:\Windows\" directory.
Set fs = CreateObject("Scripting.FileSystemObject")
'Log file name
Set logFile = fs.OpenTextFile("fileNameLogs.txt", 2, True)
'Directory you want listed
Set folder = fs.GetFolder("c:\windows\")
Set files = folder.Files
For Each file in files
wscript.echo file.name
logFile.writeline(file.name)
Next
logFile.close

vbscript to copy file from an external disk

A friend and I started building a VBScript that with the goal to copy any opened files/some specific format of docs (like pdf, pptx) when we insert an external hard disk or USB on the computer. We got our script as far as only copying all docs of a specific format from one the external hard disk/USB to my computer, but we must manually execute the script after inserting the external hard disk/USB.
What we would like the script to do:
Start automatically when an external hard disk/USB is inserted
Don't show a pop up after the copy
Possibily only copy the files (pdf,jpeg,pptx) that are opened by the user
Here is what we've done so far:
' foreach.vbs
' Testing the for each function on files
'
' BEGIN
' Create a File System Object to handle files and folders
Set fso = CreateObject("Scripting.FileSystemObject")
' Some vars
src = "C:\" ' The source of search, should be changed before use
dest = "c:\temp\1\" ' destination where we will copy files to
' It would be a bright idead to force and/or create dest before
' starting copy
fso.CreateFolder(dest)
Set ofolder = fso.GetFolder(src) ' set as object
' get all files inside the specified folder
Set allfiles = ofolder.Files
' Enter a For Each Loop that will process each of the files
For Each sfile in allfiles
' Better get all extensions in lower case
If LCASE(fso.GetExtensionName(sfile.Name)) = "bat" then
' Print out what we find
wscript.echo sfile.Name
fso.CopyFile sfile, dest
End If
Next
If I get it right, your actual question is How to detect a USB drive has been plugged in?
You'll need some event driven language to do this, not VBScript unfortunately.
But if you don't want to go with programming, why not using Task Scheduler.
P.S. Actually, this topic (I not like the infinite cycle, but) is a possible answer.

Resources