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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FileSystemObject How do i filter what i want to see?

Status
Not open for further replies.

gmagerr

Technical User
Aug 11, 2001
323
US
Hi guys, How can i display the contents of a directory and just display all files with a .doc extension for example? Also is there a way to select which directories or subdirectories you want to display? Thanks in advance.
 
Since the names are returned as string from the file and folder objects, you can do a small if check to make sure they are displayeable:
Code:
option explicit

Dim fso, fol, fil
Set fso = Server.CreateObject("Scripting.FileSystemObject")
set fol = fso.getFolder(Server.MapPath("/"))
For each fil in fol.files
   If InStr(fil.name,".doc") = len(fil.name) - 3 Then
      Response.Write fil.name & &quot;<br>&quot;
   End If
Next

Dim acceptableFolders
Dim subFol
acceptableFolders = &quot;[MyFolder] [MyOtherFolder] [YetAnotherFolder]&quot;

For each subFol in fol.subFolders
	If InStr(acceptableFolders,&quot;[&quot; & subFol.name & &quot;]&quot;) > 0 Then
		Response.Write &quot;Folder: &quot; & subFol.name
	End If
Next

Now that was on the fly, so there may be a quicker way to do it, but it should work out for what you want.

-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
For my next trick I will pull a hat out of a rabbit (if you think thats bad you should see how the pigeon feels...) :p
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top