I have this code that moves my entire structure of folder to another folder, but I only want to copy this structure to another folder, so my first folder still remains with all files and subdirectories.
I also have to use flags '-a' - to copy hidden files, '-u' - to delete files from source directory (first folder from which I copy), '-o' - existing files in destination to not overwrite and '-dx' - to copy files up to level 'x' nesting, I don't really know how to integrate this.
#include <stdio.h>
#include <stdlib.h>
#include <dos.h>
#include <iostream>
#include <dir.h>
#include <string.h>
#include <limits>
using namespace std;
char dest[PATH_MAX];
char old[PATH_MAX];
void recursiveTraverse(char* path);
int main()
{
strcpy(dest, "E:\\moved");
chdir("E:\\example");
recursiveTraverse("E:\\example");
return 1;
}
void recursiveTraverse(char* path)
{
char searchPath[PATH_MAX];
char newPath[PATH_MAX];
char moved[PATH_MAX];
int value;
struct _finddata_t fileinfo;
strcpy(searchPath, path);
strcat(searchPath, "\\*.*");
value = _findfirst(searchPath, &fileinfo);
while (_findnext(value, &fileinfo) == 0)
{
if (strcmp(fileinfo.name, "..") != 0 && strcmp(fileinfo.name, ".") != 0)
{
strcpy(moved, dest);
strcat(moved, "\\");
strcat(moved, fileinfo.name);
rename(fileinfo.name, moved);
}
if (strcmp(fileinfo.name, "..") && fileinfo.attrib & _A_SUBDIR)
{
strcpy(newPath, path);
strcat(newPath, "\\");
strcat(newPath, fileinfo.name);
strcpy(old, dest);
strcat(dest, "\\");
strcat(dest, fileinfo.name);
mkdir(dest);
recursiveTraverse(newPath);
strcpy(dest, old);
}
}
_findclose(value);
}