![]() |
![]() |
![]() |
![]() |
||||
![]() |
![]() |
![]() |
![]() |
||||
|
00001 /* ///////////////////////////////////////////////////////////////////////// 00002 * File: example_c_1.c 00003 * 00004 * Purpose: C example program for the recls core library. Demonstrates: 00005 * 00006 * - searching (via Recls_Search()) for files 00007 * - recursive operation 00008 * - display of full path of each entry 00009 * - handling of errors and reporting of error information 00010 * - elicitation of entry properties via API function calls 00011 * 00012 * Created: 29th May 2006 00013 * Updated: 18th June 2006 00014 * 00015 * www: http://www.recls.org/ 00016 * 00017 * License: Copyright (c) 2006, Synesis Software Pty Ltd. 00018 * All rights reserved. 00019 * 00020 * (Licensed under the Synesis Software Open License) 00021 * 00022 * This source code is placed into the public domain 2006 00023 * by Synesis Software Pty Ltd. There are no restrictions 00024 * whatsoever to your use of the software. 00025 * 00026 * ////////////////////////////////////////////////////////////////////// */ 00027 00028 /* recls Header Files */ 00029 #include <recls/recls.h> 00030 00031 /* Standard C Library Files */ 00032 #include <stdio.h> /* for printf() / fprintf() */ 00033 #include <stdlib.h> /* for EXIT_SUCCESS / EXIT_FAILURE */ 00034 #include <string.h> 00035 00036 /* ///////////////////////////////////////////////////////////////////////// 00037 * Macros and definitions 00038 */ 00039 00040 #ifndef RECLS_NUM_ELEMENTS 00041 # define RECLS_NUM_ELEMENTS(x) (sizeof(x) / sizeof((x)[0])) 00042 #endif /* !RECLS_NUM_ELEMENTS */ 00043 00044 /* ////////////////////////////////////////////////////////////////////// */ 00045 00046 int main() 00047 { 00048 /* Declare a search handle, define the flags (for recursive file search) 00049 * and start a search. 00050 */ 00051 hrecls_t hSrch; 00052 recls_uint32_t flags = RECLS_F_FILES | RECLS_F_RECURSIVE; 00053 recls_rc_t rc = Recls_Search(".", Recls_GetWildcardsAll(), flags, &hSrch); 00054 00055 if(RECLS_RC_NO_MORE_DATA == rc) 00056 { 00057 printf(" no matches found\n"); 00058 00059 return EXIT_SUCCESS; 00060 } 00061 else if(RECLS_FAILED(rc)) 00062 { 00063 /* The search failed. Display the error string. */ 00064 char err[1001]; 00065 size_t n = Recls_GetErrorString(rc, &err[0], sizeof(err) - 1); 00066 00067 err[n] = '\0'; 00068 00069 fprintf(stderr, "Search failed: %s\n", err); 00070 00071 return EXIT_FAILURE; 00072 } 00073 else 00074 { 00075 /* Get the details for the first entry, ... */ 00076 00077 recls_info_t entry; 00078 00079 Recls_GetDetails(hSrch, &entry); 00080 00081 do 00082 { 00083 /* ... display the full path, ... */ 00084 00085 char path[1001]; 00086 size_t cch; 00087 00088 cch = Recls_GetPathProperty(entry, &path[0], RECLS_NUM_ELEMENTS(path)); 00089 printf("%.*s\n", (int)cch, &path[0]); 00090 00091 /* ... close the entry handle, ... */ 00092 Recls_CloseDetails(entry); 00093 00094 } /* ... and get the next entry. */ 00095 while(RECLS_SUCCEEDED(Recls_GetNextDetails(hSrch, &entry))); 00096 00097 /* Close the search handle. */ 00098 Recls_SearchClose(hSrch); 00099 00100 return EXIT_SUCCESS; 00101 } 00102 } 00103 00104 /* ////////////////////////////////////////////////////////////////////// */
|
recls Library documentation © Synesis Software Pty Ltd, 2001-2006 |