Micro Focus QTP (UFT) Forums
How to know whether pen drive has files or not - 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: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: How to know whether pen drive has files or not (/Thread-How-to-know-whether-pen-drive-has-files-or-not)



How to know whether pen drive has files or not - dipashri - 01-23-2014

Please tell me these scripts.I tried a lot but I can't
1)Test Script to know whether pend rive has files or not?
2)If we copy a file (ex:song) into pen drive,how to check whether song is copied into pen drive using qtp script


RE: How to know whether pen drive has files or not - basanth27 - 01-24-2014

Hello Dipashri,
You will have to substitute the drive of your external device instead of C:\ in the below code.

find_file will search for a particular filename with its extension and report if it is found or not found. This should solve Query 1.

For Query 2 you have to use the same function but probably tweak it a bit if necessary. I will leave that for you to explore Smile

Code:
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set oWrite = objFSO.CreateTextFile("SearchResult.txt", True)
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

find_file "FileName","FileExtension"

Count = 0
Function find_file(FileName, Extension)
   Set colItems = objWMIService.ExecQuery("SELECT * FROM CIM_DataFile WHERE Drive = 'C:' AND FileName='" & filename & "' AND Extension='" & extension & "'",,48)
   For Each objItem in colItems
      oWrite.WriteLine("Found " & objItem.name)
      Count = Count + 1
   Next
  
  If Count = 0 Then
    oWrite.WriteLine("File Not Found")
  End If
End Function