sydpolo
asked on
VBSCRIPT search for file type
Hello,
Looking for a script to search in a particular folder (which has many subfolders) for media file types such as mp3, wmv etc.. and store the result on a text file.
Thank you.
Looking for a script to search in a particular folder (which has many subfolders) for media file types such as mp3, wmv etc.. and store the result on a text file.
Thank you.
ASKER
Thanks for that, question on the Query bit
strQuery="Select Name,CreationDate,LastAcce ssed,LastM odified," & _
"FileSize,Extension,Drive FROM CIM_DATAFILE WHERE Extension='" & strType & _
"' AND Drive='" & strDrive & "'"
how can i search by specific folder rather than Drive?
strQuery="Select Name,CreationDate,LastAcce
"FileSize,Extension,Drive FROM CIM_DATAFILE WHERE Extension='" & strType & _
"' AND Drive='" & strDrive & "'"
how can i search by specific folder rather than Drive?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This will get the drive and foldername and the file extension and will search for the mentioned file. The results will be stored in a text file
Dim objFSO
Dim ofolder
Dim objStream
Dim strSearch
Dim strfolderSearch
Set objFSO = CreateObject("scripting.filesystemobject")
Set objStream = objFSO.createtextfile("c:\search.txt", True)
strfolderSearch = inputbox ("Please enter the folderpath with foldername for which you want to search for Eg. C:\Delphi")
strSearch = inputbox ("Please enter the file extension for which you want to search for Eg. .bat")
CheckFolder (objFSO.getfolder(strfolderSearch)), objStream
MsgBox "File Search Completed." + vbCr + "Please check c:\search.txt for details."
Sub CheckFolder(objCurrentFolder, objtxtFile)
Dim strTemp
Dim strOutput
Dim objNewFolder
Dim objFile
Dim objStream
For Each objFile In objCurrentFolder.Files
strTemp = Right(objFile.Name, 4)
If UCase(strTemp) = UCase(strSearch) Then
strOutput = CStr(objFile.Name) + "," + CStr(objFile.Path) + "," + CStr(objFile.Size) + "," + CStr(objFile.Type) + "," + CStr(objFile.datelastaccessed)
objtxtFile.writeline strOutput
End If
Next
For Each objNewFolder In objCurrentFolder.subFolders
CheckFolder objNewFolder, objtxtFile
Next
End Sub
regards
Chandru
Open in new window