home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 106 / EnigmaAmiga106CD.iso / software / sviluppo / supralib / developer / source / subdir / main.c
Encoding:
C/C++ Source or Header  |  1999-08-30  |  2.1 KB  |  93 lines

  1. /****************************************************************
  2. *
  3. *    ---------------
  4. *   * Supra library *
  5. *    ---------------
  6. *
  7. *   -- Subdir --
  8. *   Demonstration of RecDirInit(), RecDirNextTags, RecDirFree()
  9. *
  10. *   Usage: subdir path
  11. *   path = directory path to be examined (including with it's
  12. *   subdirs).
  13. *
  14. *   This program will scan files through the entire directory
  15. *   tree, starting from a provided path.
  16. *
  17. *
  18. *   ©1995 by Jure Vrhovnik -- all rights reserved
  19. *   jurev@gea.fer.uni-lj.si
  20. *
  21. *****************************************************************/
  22.  
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <clib/exec_protos.h>
  26. #include <clib/dos_protos.h>
  27. #include <string.h>
  28. #include <proto/exec.h>
  29. #include <proto/utility.h>
  30. #include <exec/memory.h>
  31. #include <dos/dos.h>
  32. #include <utility/tagitem.h>
  33. #include <libraries/supra.h>
  34.  
  35. struct    Library        *UtilityBase;
  36. struct    RecDirInfo    rdi;
  37. char    path[50];
  38.  
  39. char    full[200];
  40. LONG    size, allsize=0, files=0;
  41. int        pos;
  42.  
  43. int    main(int argc, char *argv[])
  44. {
  45.     UBYTE err;
  46.  
  47.     UtilityBase =(struct Library *)OpenLibrary("utility.library", 0);
  48.     if (!UtilityBase) return(20);
  49.  
  50.     if (argc == 0)
  51.     {
  52.         printf("Enter directory to list: ");
  53.         gets(path);
  54.         rdi.rdi_Path = path;
  55.     } else rdi.rdi_Path = argv[1];
  56.  
  57.     rdi.rdi_Num = -1;       /* Unlimited number of subdirs deep */
  58.     rdi.rdi_Pattern = NULL; /* No pattern */
  59.  
  60.     if (RecDirInit(&rdi) == 0)
  61.     {
  62.         printf("Scanning %s\n\n", rdi.rdi_Path);
  63.  
  64.         for(;;)
  65.         {
  66.             err = RecDirNextTags(&rdi, NULL, RD_FULL, full, RD_SIZE, &size, TAG_DONE);
  67.             if (err) break;
  68.             pos = strlen(full)-25;
  69.             if (pos < 0) pos = 0;
  70.  
  71.             printf("%-25s%15ld\n", full+pos, size);
  72.             allsize += size;
  73.             files++;
  74.         }
  75.  
  76.         switch(err)
  77.         {
  78.             case DN_ERR_END:
  79.                 printf("\n%ld files -- %ld bytes listed\n", files, allsize);
  80.                 break;
  81.             default:
  82.                 printf("error, terminating...\n");
  83.         }
  84.     }
  85.     else
  86.     {
  87.         printf("Path not found.\n");
  88.     }
  89.     CloseLibrary((struct Library *)UtilityBase);
  90.     return(0);
  91. }
  92.  
  93.