Back to the WFC main page
CFileDirectory
$Revision: 4 $
Description
This class lets you get a list of filenames (complete path)
contianed in a directory. It will also recurse meaning it will
retrieve all filenames for the directory you want and any
subdirectories too.
Constructors
CFileDirectory()
-
Constructs the object.
Methods
void Close( void )
-
In staying with the file motif, we should be able
to close that which is opened.
BOOL Open( const CString& directory_name )
-
Returns TRUE if
directory_name
is not empty.
BOOL Read( CStringArray& filenames )
-
This method will fill
filenames
with the complete path to
the files in the directory specified in the Open() call.
BOOL Read( FILE_ACTION_FUNCTION action_to_take, void * action_parameter )
-
This method will call the
action_to_take
function with the
supplied action_parameter
for every file in the directory
specified in the Open() call.
action_to_take
will be passed a string containing the complete
path to the file.
BOOL ReadRecursively( CStringArray& filenames )
-
This method will fill
filenames
with the complete path to
the files in the directory and all subdirectories of the directory
specified in the Open() call.
BOOL ReadRecursively( FILE_ACTION_FUNCTION action_to_take, void * action_parameter )
-
This method will call the
action_to_take
function with the
supplied action_parameter
for every file in the directory
and all subdirectories of the directory specified in the Open() call.
action_to_take
will be passed a string containing the complete
path to the file.
Example
#include <wfc.h>
#pragma hdrstop
BOOL action_to_take( void * action_parameter, const CString& complete_filename )
{
WFCTRACEINIT( TEXT( "action_to_take()" ) );
DWORD * file_counter_p = reinterpret_cast< DWORD * >( action_parameter );
(*file_counter_p)++; // increment the counter
// Print the filename
_tprintf( TEXT( "%s\n" ), (LPCTSTR) complete_filename );
}
int _tmain( int number_of_command_line_arguments, LPCTSTR command_line_arguments[] )
{
WFCTRACEINIT( TEXT( "_tmain()" ) );
int argument_index = 1;
DWORD total_number_of_files = 0;
CFileDirectory directory;
while( argument_index < number_of_command_line_arguments )
{
if ( directory.Open( command_line_arguments[ argument_index ] ) != FALSE )
{
directory.Read( action_to_take, &total_number_of_files );
}
}
_tprintf( "Processed %lu files.\n", total_number_of_files );
return( EXIT_SUCCESS );
}
Copyright, 2000, Samuel R. Blackburn
$Workfile: CFileDirectory.cpp $
$Modtime: 1/17/00 9:02a $