Reputation: 870
I have the following directory structure:
Main1
+-Parent1
+-File1
+-File2
+-Parent2
+-File3
+-File4
+-Parent3
+-File5
+-File6
...
And I am looking to copy to a new directory. However, if the Parent folder already exists, regardless of it file contents, I do not want to copy it.
Main2
+-Parent2
+-File7
+-File8
So if I am copying from Main1
to Main2
, the Parent2
folder in Main1
would not copy, nor would its contents.
In the end, it should end up looking like this:
Main1
+-Parent2
+-File3
+-File4
Main2
+-Parent1
+-File1
+-File2
+-Parent2
+-File7
+-File8
+-Parent3
+-File5
+-File6
...
Upvotes: 0
Views: 47
Reputation: 176
This is the code I use to read the list of folders in any folder. You can use this to get what you requested.
// http://stackoverflow.com/questions/612097/how-can-i-get-the-list-of-files-in-a-directory-using-c-or-c herohuyongtao
std::vector<std::string> get_all_folder_names_within_folder(std::string folder)
{
std::vector<std::string> names;
char search_path[200];
sprintf_s(search_path, 200, "%s/*.*", folder.c_str());
WIN32_FIND_DATA fd;
HANDLE hFind = ::FindFirstFile(search_path, &fd);
int i = 0;
if(hFind != INVALID_HANDLE_VALUE) {
do {
// read all (real) files in current folder
// , delete '!' read other 2 default folder . and ..
if( (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ) {
if (i >= 2){
names.push_back(fd.cFileName);
}
}
i++;
}while(::FindNextFile(hFind, &fd));
::FindClose(hFind);
}
return names;
}
Upvotes: 2