title: "mkdir()" not working
body: <p>Hi I am trying to create a recurive copy function that emulates the CP program in unix. So basically if i run the program with -r option it will copy a folder with all of it's sub directories. I am using the folling function.</p>
  
  <pre><code>void copyDirectory(char *destDir, char *dirName)
  {
      printf("copyDirectory run \n");
  
      int charCnt;
      int srcFd;
      int dstFd;
      char* sourcePath;
      char* destPath;
  
      DIR *dir = opendir(dirName);
      if(dir == NULL){
          return;
      }
  
      char Path[256], *EndPtr = Path;
  
      struct dirent *e;
      strcpy(Path, dirName);
  
      EndPtr += (strlen(dirName)+1);
      while((e = readdir(dir)) != NULL){
          sourcePath = malloc(strlen(Path)+1+strlen(e-&gt;d_name));
          destPath = malloc(strlen(destDir)+1+strlen(Path));
          strcpy(destPath, destDir);
          strcat(destPath, slash);
          strcat(destPath, Path);
  
          if (0 != access(destPath, F_OK)) {
              mkdir(destPath,0777);
              printf("mkdir %s \n", destPath);
          }
  
          strcpy(sourcePath, Path);
          strcat(sourcePath, slash);
          strcat(sourcePath, e-&gt;d_name);
  
          printf("copyDirectory destPath = %s \n", destPath);
          printf("copyDirectory sourcePath = %s \n", sourcePath);
  
          if(strcmp(e-&gt;d_name, dott) == 0){
              continue;
          }
          if(strcmp(e-&gt;d_name, dot) == 0){
              continue;
          }
  
  
          if(whatType(sourcePath) == 1){
              copyDirectory(destDir, sourcePath);   
          }
          else{
              /* copyFile(destPath, sourcePath);*/
          } 
  
          free(sourcePath);
          free(destPath);
      }
  }
  </code></pre>
  
  <p>This seems to work fine if i run the program using the following command line.</p>
  
  <pre><code>Mycopy Sourcefolder/ DestinationFoler/
  </code></pre>
  
  <p>but when I run it with this command line, the mkdir function inside my program stops working.</p>
  
  <pre><code>Mycopy Sourcefolder/Subfolder/ DestinationFoler/
  </code></pre>
  
  <p>The weird thing is I put a printf marker inside the mkdir call to see what destPath was and the formatting looks no different to when I call the program not using a subfoler. What is going on?</p>