Micro Focus QTP (UFT) Forums
How can i write a script in QTP to poll a folder for a new file? - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: How can i write a script in QTP to poll a folder for a new file? (/Thread-How-can-i-write-a-script-in-QTP-to-poll-a-folder-for-a-new-file)



How can i write a script in QTP to poll a folder for a new file? - geethwind - 07-16-2009

Hello

can anyone help me with one of the below things?

1. Can i be able to check a folder from QTP for any newfile with a given name?

2. Or can i be able to check the Websphere MQ record from QTP.

Basically I am running a testcase which calls a webservice to run but there is no direct response from Webservice it creates a record in the WS Que and creates and XML file in a specific folder . Is there any way i can check for one of this to make sure that my test is passed.

Thanks allot for the help.

-G


RE: How can i write a script in QTP to poll a folder for a new file? - KVK - 07-16-2009

Hi,

The answer for you first question is Yes. We can verify whether a folder or a file exists using fso object

FolderExists Method:
Code:
Returns True if a specified folder exists; False if it does not.
   Dim fso, msg, fldr
   fldr = "C:\Windows"  
   Set fso = CreateObject("Scripting.FileSystemObject")
   If (fso.FolderExists(fldr)) Then
      msg = fldr & " exists."
   Else
      msg = fldr & " doesn't exist."
   End If

FileExists Method:-
Code:
Returns True if a specified file exists; False if it does not.
The following example illustrates the use of the FileExists method.
   Dim fso, msg, filespec
   filespec = "C:\boot.ini"
   Set fso = CreateObject("Scripting.FileSystemObject")
   If (fso.FileExists(filespec)) Then
      msg = filespec & " exists."
   Else
      msg = filespec & " doesn't exist."
   End If


-Mr.K


RE: How can i write a script in QTP to poll a folder for a new file? - geethwind - 07-17-2009

Thanks allot Mr.K,

Thats working fine.. Can I be able to check the folders on the server instead of C:\ , do i need to link anywhere that server??


RE: How can i write a script in QTP to poll a folder for a new file? - KVK - 07-17-2009

Yes, You can by giving the server ip address or computer name

Code:
Dim fso, msg, filespec
filespec = "\\192.168.1.1\c$\boot.ini"
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(filespec)) Then
msgbox filespec & " exists."
Else
msgbox filespec & " doesn't exist."
End If


Let me know if this works

-Mr.K


RE: How can i write a script in QTP to poll a folder for a new file? - geethwind - 07-18-2009

Thanks .K

its working fine...u rock..


RE: How can i write a script in QTP to poll a folder for a new file? - deepaksporty - 05-19-2011

Another thing which you would want to do here is to keep on checking the folder or file exist since you mentioned polling...this code would check once...but you need to develop a logic to check the availability for some time.