Tuesday, August 18, 2009

Recursive search in vbscript.

It was this particular thing in vbscript which was lurring me from many days. I had written a small script for downloading Test Cases from Quality Center to Excel. QC 9.5 provides this as in built functionality but we had some old systems where in we had to pull all existing cases in Excel. The code was ready and I found that it needed exact path from QC logical folder structure to find all cases within it. There was a dire need to search within the given path to find all sub folders and test cases within them.

There was another requirement to replace one particular string from many script files stored on a server where quality center was installed. I had to replace all scripts which get saved on qc file system which had a particular string present in it. All test cases of type QUICK_TEST get saved with Script.mts file holding the actual textual part of script.

Here is a snippet to find particular file type (e.g.: Here i have searched for .mts file type as it was our requirement) within given folder and it searches in all sub folders present in it:

strDir = "D:\rohan\test"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objDir = objFSO.GetFolder(strDir)RecursiveFunc (objDir)

Sub RecursiveFunc(Dir_Passed)
For Each Item_File In Dir_Passed.Files
If LCase(Right(CStr(Item_File.Name), 3)) = "mts" Then
wscript.Echo Dir_Passed & "\" & Item_File.Name
End If
Next

For Each Item_Fldr In Dir_Passed.SubFolders
'wscript.Echo Item_Fldr.Name & " recursed"
RecursiveFunc (Item_Fldr)
Next
End Sub

2 comments:

mts to mov convert said...

Nice post.

Unknown said...

mts file converter mov convert avchd mts to iPhone mov
it seems that we have similar interesting.