TScanDir

        V1.00 (11-29-98)


        TScanDir is a component for scanning directories and subdirectories for files matching a certain file mask.

          Usage
          Reference
          Examples

        Usage

        TScanDir is a not visible component. Drop a copy of it onto a form or create a TScanDir object at run time:

          TScanDir *scanDir;
          scanDir=new TScanDir (this);

        Now the properties and methods are accessable.


        Reference

          Data Types
          SCANDIRFILE
          SCANDIRFOLDER

          Variables
          int FolderCount;
          FileCount

          Properties
          AnsiString Path;
          bool RecursiveScan;
          AnsiString Mask;

          Methods
          void __fastcall Execute(void);

          Events
          OnFileFound
          OnFolderFound
          OnFolderProcessed

        SCANDIRFILE

          This structure gives information about a file found during the scan process. For easier access, the filename and path is split into several parts.

          typedef struct
          {
              AnsiString Path;      // The path, including final backslash, e.g. c:\\temp\\
              AnsiString Filename;  // Filename with extension, e.g. myfile.doc
              AnsiString FullName;  // Filename with path, e.g. c:\\temp\\myfile.doc
              AnsiString NameOnly;  // Filename without extension, e.g. myfile
              AnsiString Extension; // Extension without ".", e.g. doc
              long Length;          // Filelength in bytes
          } SCANDIRFILE;

        SCANDIRFOLDER

          This structure gives information about a folder found during the scan process. For easier access, the path is split into several parts.

          typedef struct
          {
              AnsiString Path;       // Parent path, including final backslash, e.g. c:\\temp\\
              AnsiString Foldername; // Foldername, no path, no backslashes, e.g. myfolder
              AnsiString FullName;   // Foldername with path and backslash, e.g. c:\\temp\\myfolder\\
          } SCANDIRFOLDER;

        int FolderCount;

          This variable holds the number of subfolders found after a scan process.

        int FileCount;

          This variable holds the number of files found (matching the file mask) after a scan process.

        AnsiString Path;

          This propery sets the path the component scans through. You can end the path with a backslash, but you don't have to.

        bool RecursiveScan;

          This propery selects whether component scans only the directory entered as the Path property or all it's subsequent sub directories.

        AnsiString Mask;

          This propery sets the mask that is used when scanning for files. Any Dos style mask is allowed. If you leave it empty, the component will use *.*

        void __fastcall Execute(void);

          Call this method to start scanning with the parameters entered in the property section. The component then fires the events you assigned for every file or folder it finds.

        void __fastcall (__closure *OnFileFound)(System::TObject* Sender, SCANDIRFILE &scandirfile);

          This event is fired for every file found matching the mask.

        void __fastcall (__closure *OnFolderFound)(System::TObject* Sender, SCANDIRFOLDER &folder);

          This event is fired for every folder found. The event is fired before this folder is scanned for any subfolders or files.

        void __fastcall (__closure *OnFolderProcessed)(System::TObject* Sender, SCANDIRFOLDER &folder);

          This event is fired after the folder has been scanned fot subfolders and files.


        Example

          The following code generates a list of the DLLs in your Windows directory. The TScanDir component in this example is created on the fly and it's properties set manually. If you add the component to your form and set the properties and events in the object inspector, you can save most of the lines in the Button1Click fuction.

          void __fastcall TForm1::Button1Click(TObject *Sender)
          {
            TScanDir *ScanDir1=new TScanDir(this);
            ScanDir1->Path="c:\\windows";
            ScanDir1->Mask="*.dll";
            ScanDir1->RecursiveScan=true;
            ScanDir1->OnFileFound=ScanDir1FileFound;
            ScanDir1->OnFolderFound=ScanDir1FolderFound;
            ScanDir1->OnFolderProcessed=ScanDir1FolderProcessed;
            ScanDir1->Execute();
            delete ScanDir1;
          }
          //---------------------------------------------------------------------------
          void __fastcall TForm1::ScanDir1FileFound(TObject *Sender, SCANDIRFILE &scandirfile)
          {
            Memo1->Lines->Add(scandirfile.Filename);
          }
          //---------------------------------------------------------------------------
          void __fastcall TForm1::ScanDir1FolderFound(TObject *Sender, SCANDIRFOLDER &folder)
          {
            Memo1->Lines->Add("===== Entering "+folder.FullName+" ========");
          }
          //---------------------------------------------------------------------------
          void __fastcall TForm1::ScanDir1FolderProcessed(TObject *Sender, SCANDIRFOLDER &folder)
          {
            Memo1->Lines->Add("===== Leaving "+folder.FullName+" ========");
          }
          //---------------------------------------------------------------------------


        Back