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