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
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 Smile](https://www.learnqtp.com/forums/images/smilies/smile.gif)
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.
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.