libsheepy

C lib for handling text files, strings and json like data structure with an object oriented system
git clone https://spartatek.se/git/libsheepy.git
Log | Files | Refs | README | LICENSE

forest.c (1236B)


      1 //
      2 
      3 #include "../release/libsheepyObject.h"
      4 
      5 #define internal static
      6 
      7 #include <string.h>
      8 #include <stdio.h>
      9 
     10 #ifndef unitTest
     11 #endif
     12 int MAIN(int ARGC, char** ARGV);
     13 
     14 int argc; char **argv;
     15 
     16 #ifndef unitTest
     17 // Remove main when running the unit tests
     18 #define MAIN   main
     19 #endif
     20 int MAIN(int ARGC, char** ARGV) {
     21   int d UNUSED;
     22 
     23   argc = ARGC; argv = ARGV;;// copy folder tree (without the files) in argument 1 path to argument 2 path
     24 
     25   // Steps
     26   // check arguments
     27   // list folders in path 1
     28   // create folders in path 2
     29 
     30   // check arguments
     31   if (argc < 3) {
     32     puts(BLD RED "At least 2 arguments are needed" RST);
     33     XFAILURE;
     34   }
     35 
     36   // list folders in path 1
     37   cleanSmallArrayP(dirs) = walkDirDirG(rtSmallArrayt, argv[1]);;
     38 
     39   //logG(dirs);
     40 
     41   // create folders in path 2
     42   size_t len            = strlen(argv[1]);
     43   iter(dirs, src) {
     44     castS(sSrc, src);
     45     // remove argument 1 from source path
     46     sliceG(sSrc, len, 0);
     47     if (!isEmptyG(sSrc)) {
     48       // create path in argument 2 folder (destination)
     49       cleanSmallStringP(dstPath) = allocSmallString(argv[2]);
     50       pushG(dstPath, "/");
     51       appendG(dstPath, sSrc);
     52       putsG(dstPath);
     53       // make dir in destination
     54       mkdirParentsG(dstPath);
     55     }
     56   }
     57 }