Visual Basic Code of the Week (COTW)
http://www.codeoftheweek.com
Issue #80
Online Version at http://www.codeoftheweek.com/membersonly/bi/0080.html (paid subscribers only)
All content and source code is Copyright (c) 1999 by C&D Programming Corp. No part of this issue can be reprinted or distributed in any manner without express written permission of C&D Programming Corp.

Congratulations!

Tracy Martin is the winner of an annual subscription to Code of the Week for submitting this weeks source code.

Get your Free Year of Code of the Week!!!

For the next month we are offering a free annual subscription to anyone that submits source code for an issue which gets published. If you have some useful source code that would be valuable for our members, fill out the form at http://www.codeoftheweek.com/submissions.html

Please make sure all source code is tested and is in working condition. We are looking for all types of source from database access routines to API calls to graphics routines. We are not looking for one or two lines tricks at this time (this will be a future offering) . The source code should be at least 10 or 15 lines of long, preferably longer. It should be commented or at least readable by the average programmer.

If you are currently a member of Code of the Week we will extend your subscription an additional year.

Cool Software

Download a free copy of NetMon - Your Internet Performance Monitor at http://www.codeoftheweek.com/netmon/index.html

In this Issue

In this issue we show a very fast way to search for files.

This source code is designed for VB 4.0 32-bit and up. Questions? Email us at questions@codeoftheweek.com.

cFindFiles

The cFindFiles class module was written by Tracy Martin with some small modifications by C&D Programming Corp. It contains a couple of methods for getting files and information about files it has found.

If you have any questions about using this class, let us know at questions@codeoftheweek.com

Functions

Public Function FindFile(ByVal pstrName As String) As Boolean

This is the start of the search routine. You would call this with a parameter such as "e:\temp\*.xls" to find all files with the extension xls. It will return True if a file was found and False if it was not found. After calling this function you can use any of the Properties listed below to get additional information provided it returned True.

Public Function FindNextFile() As Boolean

This routine needs to be called until it returns False in order to retrieve all the matching files. After calling this function you can use any of the Properties listed below to get additional information provided it returned True.

Methods

Public Sub FindClose()

Completes one search and allows you to begin another.

Properties

Returns

See each function/properties for details.

Sample Usage

The below sample describes how to use the cFindFiles class. It will show how many files are located in the E:\TEMP directory.

Option Explicit

Private Sub FindTest()
    Dim Fnd As cFindFiles
    Dim bContinue As Boolean
    Dim lCount As Long

    Set Fnd = New cFindFiles

    bContinue = Fnd.FindFile("e:\temp\*.*")
    While bContinue
        lCount = lCount + 1
        bContinue = Fnd.FindNextFile
    Wend
    MsgBox "Found " & lCount & " matching files."
End Sub

Source Code

To see the source code for this issue you must be a subscriber to Code of the Week. If you are a subscriber the source code is available at the following address: http://www.codeoftheweek.com/membersonly/bi/0080.html


This document is available on the web

Paid subscribers can view this issue in HTML format. There is no additional source or information in the HTML formatted document. It just looks a little better since we have included some HTML formatting. Just point your browser to link at the top of this document.

Other links

Contact Information

C&D Programming Corp.
PO Box 20128
Floral Park, NY 11002-0128
Phone or Fax: (212) 504-7945
Email: info@codeoftheweek.com
Web: http://www.codeoftheweek.com