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

Searching Files 1

Status
Not open for further replies.

zzfive03

Programmer
Jun 11, 2001
267
Good Morning.

I have a subroutine that connects to a virtural drive, and searches for .txt files. When It finds one, it will print it out on the page. The problme is the subroutine takes forever because it is sorting thru all kinds of other files. Is there a built in funciton (or just a more effecent way) to search for .txt (or *.anything). Here is my current procedure for doing this task:

For Each objFile in objSubFolder.Files
FExtBegPos = InStrRev(objFile.Name, ".")
FExtTotal = len(objFile.Name)
FExt = Right(objFile.Name, FExtTotal - FExtBegPos)
If FExt = "FSZ" or FExt = "fsz" Then
do something
End If

Thanks for any adivce.

 
Observation. Properties that are used more than once should be extracted first. You call objFile.Name three times.
Code:
Dim strFileName as string
For Each objFile in objSubFolder.Files
     strFileName = Lcase$(objFile.Name)
     if strFileName like "*.fsz" then
         do something
     End If
Next
BTW. There is a FSO method for getting the extension
"GetExtensionName Method
Description
Returns a string containing the extension name for the last component in a path.
Syntax
object.GetExtensionName(path)"



 
thanks..

hum..I get this..

Microsoft VBScript runtime error '800a0023'
Sub or Function not defined
/fsz/default.asp, line 24

Here is my Line 24:
If strFileName Like "*.fsz" Then



 
Well shoot. There is not a like operator in VBScript.
Code:
For Each objFile in objSubFolder.Files
     strFileName = Lcase(objFile.Name)
     'Assuming FS is the FileSystemObject
     if Lcase(fs.GetExtensionName(strFileName)) = "fsz" then
         do something
     End If
Next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top