Name

wfindfirst, wfindnext, findclose
- Provides information about the first instance of a file name that matches the file specified in the filespec argument and wfindnext finds the next name.

Library

libc.lib

Synopsis

  #include <wchar.h>
  long wfindfirst (const wchar_t* filespec, struct _wfinddata_t* fileinfo);
  int wfindnext (intptr_t handle, struct _wfinddata_t * fileinfo);
  int findclose (intptr_t handle);


Return values

If successful, wfindfirst return a unique search handle identifying the file or group of files matching the filespec specification, which can be used in a subsequent call to wfindnext or to findclose. Otherwise, wfindfirst returns -1 and sets errno accordingly.

If successful, wfindnext returns 0. Otherwise, returns -1 and sets errno to a value indicating the nature of the failure.

If successful, findclose returns 0. Otherwise, it returns -1 and sets errno to ENOENT


Errors

[EINVAL]
  Invalid parameter: filespec or fileinfo was NULL. Or, the operating system returned an unexpected error.

[ENOENT]
  File specification that could not be matched.


Detailed description

The wfindfirst function provides information about the first instance of a file name that matches the file specified in the filespec argument. Any wildcard combination supported by the host operating system can be used in filespec. File information is returned in a _wfinddata_t structure, defined in wchar.h. The _wfinddata_t structure includes the following elements.

unsigned attrib File attribute

time_t time_create
  Time of file creation (-1L for Symbian)

time_t time_access
  Time of the last file access (-1L for Symbian)

time_t time_write Time of the last write to file

size_t size Length of the file in bytes

wchar_t name[260] Null-terminated name of matched file/directory, without the path

This attribute is returned in the attrib field of the _wfinddata_t structure and can have the following values (defined in wchar.h).

_A_ARCH Archive.
_A_HIDDEN
  Hidden file.
_A_NORMAL
  Normal.
_A_RDONLY
  Read-only.
_A_SYSTEM
  System file.

The wfindnext finds the next name, if any, that matches the filespec argument in a previous call to wfindfirst and then alters the fileinfo structure contents accordingly.

The findclose closes the specified search handle and releases the associated resources.


Examples

#include <wchar.h>
int main( void )
{
   struct _wfinddata_t c_file;
   intptr_t hFile;
   // Find  .txt file in current directory
   if( (hFile = wfindfirst( L"*.txt", &c_file )) == -1L )
      printf( "No *.txt files in current directory" );
   else
   {
        int i = 1;
      do {
             wprintf( L" File %d = %s ",i,c_file.name);
             i++;
                     } while( wfindnext( hFile, &c_file ) == 0 );
      findclose( hFile );
   }
   return 0 ;
}  

         

Output

File 1 = test1.txt
File 2 = test2.txt

         


See also


Bugs

Does not support any attribute to find out the sub-directories (i.e., attribute _A_SUBDIR not supported).

Feedback

For additional information or queries on this page send feedback

© 2005-2007 Nokia

Top