Posts: 4
Threads: 4
Joined: Jan 2014
Reputation:
0
01-23-2014, 10:19 PM
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
Posts: 1,003
Threads: 1
Joined: Jul 2009
Reputation:
5
01-24-2014, 06:56 AM
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
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
Basanth
Give a fish to a man and you feed him for a day..Teach a man how to fish and you feed him for life.