Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use FileSysObj to List Specific Files? 1

Status
Not open for further replies.

Caper

Technical User
Aug 11, 2001
9
US
Hello All,

I'm using the following FileSystemObject code to list and count the files in a given folder:

Code:
Private Sub Command1_Click()
Dim fsoSysObj As New FileSystemObject
Dim fld1 As Folder, fld2 As Folder, strPath As String
Dim fil1 As File
Dim i As Integer 'counter variable
i = 0
strPath = App.path
Set fld1 = fsoSysObj.GetFolder(strPath)
For Each fil1 In fld1.Files
 Debug.Print fil1.Name
 i = i + 1
Next
End Sub

From here it seems easy enough to load the file list into an array for use in my program, and use the count for some other stuff I have planned, but can I use the FSO to be more selective and only grab files with a certain extension? Or do I have to use string manipulation on the file names once I've got them loaded into an array? Or is there some other/better approach than the FSO (which seems to otherwise work real well).

Thanks for any thoughts!
 
I don't think that the File Object can directly provide you the extension, but is does have the .ShortName property which returns the filename in the standard 8.3 format, so you could then do

If (Right(thisfile.ShortName, 3) = "your extension") Then
Add to Array
End If
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
You can actually do this with FSO:

strFileExtension = fso.GetExtensionName(strInputFile)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top