Thursday, October 6, 2011

Getting File Path List Using Wild Card Characters

In this article, I would like to share how to get the file path for the files which are residing in a folder using wild card.

Consider the case where we have a folder containing text files temp.txt, tem.txt, temp1.txt, temp2.txt.

In the above text file list if we want to get path for the files using “temp*.txt” wild card, GetFiles (System.IO.Directory) method can be used.

Dim inFile,oColFilesList,oArrayList,oDI

Set oArrayList=DotNetFactory.CreateInstance("System.Collections.ArrayList","")
Set oDI=DotNetFactory.CreateInstance("System.IO.Directory","mscorlib")

Set oColFilesList=oArrayList.Adapter(oDI.GetFiles("C:\Files List","temp*.txt"))

For inFile=0 to Cint(oColFilesList.Count)-1
Msgbox oColFilesList(inFile)
Next

Set oArrayList=Nothing
Set oDI=Nothing
Set oColFilesList=Nothing
The above code will retrieve paths of temp.txt, temp1.txt, and temp2.txt files but not for tem.txt file.

No comments:

Post a Comment