FindFiles Class Reference

This class can be used for searching directories for files. It is basically equivalent to the. More...

#include <fileutil.h>

List of all members.

Public Member Functions

 FindFiles ()
BOOL StartFindingFiles (String_256 *FileSpecifier)
 Scans a given directory for files matching a particular name. Same as FileUtil::StartFindingFiles but being a class is re-entrant and returns directories so that you can do recursive searches.
BOOL FindNextFile (String_256 *FoundFile, BOOL *IsDirectory)
 Finds the next file, if any. See StartFindingFiles for example search code Notes: ** Note that this will not return system/hidden files **.
BOOL StopFindingFiles ()
 Stops a directory scan To find files, do something like the following See StartFindingFiles for example search code DO NOT CALL THIS FUNCTION if StartFindingFiles failed. Call this function exactly once for each call to StartFindingFiles.

Private Member Functions

 CC_DECLARE_MEMDUMP (FindFiles)

Private Attributes

String_256 m_SearchPath


Detailed Description

This class can be used for searching directories for files. It is basically equivalent to the.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
09/01/97
See also:

Definition at line 179 of file fileutil.h.


Constructor & Destructor Documentation

FindFiles::FindFiles  )  [inline]
 

Definition at line 184 of file fileutil.h.

00184 {};


Member Function Documentation

FindFiles::CC_DECLARE_MEMDUMP FindFiles   )  [private]
 

BOOL FindFiles::FindNextFile String_256 FoundFile,
BOOL *  IsDirectory
 

Finds the next file, if any. See StartFindingFiles for example search code Notes: ** Note that this will not return system/hidden files **.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> based on Jason code.
Date:
12/9/96
Parameters:
if return value is TRUE [OUTPUTS] FoundFile will be filled in with the LEAF filename ("bob.xar") of a found IsDirectory will be TRUE if the file is a directory, else FALSE, if return value is FALSE FoundFile will be set to an empty string. IsDirectory will be FALSE.
Returns:
TRUE if it found a(nother) file matching the filespec. FALSE if there are no (more) matching files
See also:
FindFiles::StartFindingFiles; FindFiles::StopFindingFiles

FileUtil::StartFindingFiles FileUtil::FindNextFile; FileUtil::StopFindingFiles

Definition at line 771 of file fileutil.cpp.

00772 {
00773     ERROR3IF(FoundFile == NULL || IsDirectory == NULL, "Illegal NULL param");
00774 
00775     BOOL result = TRUE;
00776 
00777     while (result)
00778     {
00779         if (m_SearchHandle == INVALID_HANDLE_VALUE)
00780         {
00781             // find first
00782             m_SearchHandle = ::FindFirstFile((TCHAR *)m_SearchPath, &m_SearchData);
00783             result = (m_SearchHandle != INVALID_HANDLE_VALUE);
00784         }
00785         else
00786         {
00787             // find next
00788             result = ::FindNextFile(m_SearchHandle, &m_SearchData);
00789         }
00790 
00791         if (result)
00792         {
00793             // Only return "files" which are not system or hidden
00794             const DWORD AttrMask = FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM;
00795             const DWORD AttrDirMask = FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM;
00796             TCHAR * ThisDir = ".";
00797             TCHAR * ParentDir = "..";
00798             INT32 len = camStrclen(m_SearchData.cFileName);
00799             if ((m_SearchData.dwFileAttributes & AttrMask) == 0)
00800             {
00801                 // OK, it's a safe file to return, so return it
00802                 *FoundFile = m_SearchData.cFileName;
00803                 *IsDirectory = FALSE;
00804                 return TRUE;
00805             }
00806             else if (((m_SearchData.dwFileAttributes & AttrDirMask) == 0) &&
00807 //                    (cc_lstrncmp(m_SearchData.cFileName, ThisDir, len) != 0) &&
00808 //                    (cc_lstrncmp(m_SearchData.cFileName, ParentDir, len) != 0))
00809                       (camStrncmp(m_SearchData.cFileName, ThisDir, len) != 0) &&
00810                       (camStrncmp(m_SearchData.cFileName, ParentDir, len) != 0))
00811             {
00812                 // OK, it's a safe directory to return, so return it
00813                 *FoundFile = m_SearchData.cFileName;
00814                 *IsDirectory = TRUE;
00815                 return TRUE;
00816             }
00817         }
00818     }
00819 
00820     *FoundFile = TEXT("");
00821     *IsDirectory = FALSE;
00822     return FALSE;
00823 }

BOOL FindFiles::StartFindingFiles String_256 FileSpecifier  ) 
 

Scans a given directory for files matching a particular name. Same as FileUtil::StartFindingFiles but being a class is re-entrant and returns directories so that you can do recursive searches.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> based on Jason code.
Date:
9/1/97
Parameters:
FileSpecifier - A full pathname specifying the file(s) to search for. [INPUTS] You may include ? and * wildcards
For example, c:.xar one specific file c:\*.txt all .txt files c:\*.* all files

Returns:
TRUE if the scan was successfully started, FALSE otherwise
See also:
FindFiles::FindNextFile; FindFiles::StopFindingFiles

FileUtil::StartFindingFiles FileUtil::FindNextFile; FileUtil::StopFindingFiles

Definition at line 738 of file fileutil.cpp.

00739 {
00740     ERROR3IF(FileSpecifier == NULL, "Duff FileSpecifier param");
00741 
00742     m_SearchHandle = INVALID_HANDLE_VALUE;
00743     m_SearchPath = *FileSpecifier;
00744 
00745     return(TRUE);
00746 }

BOOL FindFiles::StopFindingFiles void   ) 
 

Stops a directory scan To find files, do something like the following See StartFindingFiles for example search code DO NOT CALL THIS FUNCTION if StartFindingFiles failed. Call this function exactly once for each call to StartFindingFiles.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> based on Jason code.
Date:
12/9/96
Returns:
True if completed ok, False otherwise.
See also:
FindFiles::StartFindingFiles; FindFiles::FindNextFile

FileUtil::StartFindingFiles FileUtil::FindNextFile; FileUtil::StopFindingFiles

Definition at line 843 of file fileutil.cpp.

00844 {
00845     if (m_SearchHandle != NULL)
00846         ::FindClose(m_SearchHandle);
00847 
00848     m_SearchHandle = INVALID_HANDLE_VALUE;
00849 
00850     return TRUE;
00851 }


Member Data Documentation

String_256 FindFiles::m_SearchPath [private]
 

Definition at line 192 of file fileutil.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 03:54:19 2007 for Camelot by  doxygen 1.4.4