C/C++ User's Journal STLSoft - ... Robust, Lightweight, Cross-platform, Template Software ... ATLSTL - where the Standard Template Library meets the Active Template Library COMSTL - where the Standard Template Library meets the Component Object Model
Synesis Software InetSTL - where the Standard Template Library meets the Internet UNIXSTL - Template Software for the UNIX Operating System WinSTL - where the Standard Template Library meets the Win32 API

example_c_8.c

[recls Core API] This example enumerates all files under the current directory and prints out their full paths squeezed into a fixed width. Also temporarily displays search progress. It illustrates the following features of the core API:

00001 /* /////////////////////////////////////////////////////////////////////////////
00002  * File:        example_c_8.c
00003  *
00004  * Purpose:     C example program for the recls core library. Demonstrates:
00005  *
00006  *                - elicitation of all roots (via Recls_GetRoots()), and
00007  *                  selected roots (via Recls_GetSelectedRoots()), on host
00008  *                  system
00009  *                - determination of total size of all files per root (via
00010  *                  Recls_CalcDirectorySize())
00011  *
00012  * Created:     17th June 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     /* Display all the roots on the host system. */
00049     {
00050         recls_root_t    roots[26];
00051         size_t          numRoots    =   Recls_GetRoots(&roots[0], RECLS_NUM_ELEMENTS(roots));
00052         size_t          i;
00053 
00054         printf("All roots on host system:\n");
00055         for(i = 0; i < numRoots; ++i)
00056         {
00057             printf("  %s\n", roots[i].name);
00058         }
00059         printf("\n");
00060     }
00061 
00062     /* Display the fixed, optical and ram-drive roots on the host system,
00063      * and calculate their size.
00064      */
00065     {
00066         unsigned        rootTypes   =   RECLS_ROOTS_F_FIXED_DRIVES | RECLS_ROOTS_F_CDROM_DRIVES | RECLS_ROOTS_F_RAM_DRIVES;
00067         size_t          numRoots    =   Recls_GetSelectedRoots(NULL, 0, rootTypes);
00068         recls_root_t    *roots      =   (recls_root_t*)malloc(sizeof(recls_root_t) * numRoots);
00069         size_t          i;
00070 
00071         numRoots = Recls_GetSelectedRoots(&roots[0], numRoots, rootTypes);
00072 
00073         printf("Measuring root directories of selected roots on host system:\n");
00074         for(i = 0; i < numRoots; ++i)
00075         {
00076 #if defined(RECLS_PLATFORM_IS_WIN32)
00077             unsigned long   size = (unsigned long)Recls_CalcDirectorySize(roots[i].name).QuadPart;
00078 #else /* ? OS */
00079             unsigned long   size = (unsigned long)Recls_CalcDirectorySize(roots[i].name);
00080 #endif /* OS */
00081 
00082             printf("  %s : %lu\n", roots[i].name, (unsigned long)size);
00083         }
00084         printf("\n");
00085 
00086         free(roots);
00087     }
00088 
00089     return EXIT_SUCCESS;
00090 }
00091 
00092 /* ////////////////////////////////////////////////////////////////////// */

recls Library documentation © Synesis Software Pty Ltd, 2001-2006