Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.
."|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
bool Utils::copyDir(const QString source, const QString destination, const bool override) {
QDir directory(source);
bool error = false;
if (!directory.exists()) {
return false;
}
QStringList dirs = directory.entryList(QDir::AllDirs | QDir::Hidden);
QStringList files = directory.entryList(QDir::Files | QDir::Hidden);
QList<QString>::iterator d,f;
for (d = dirs.begin(); d != dirs.end(); ++d) {
if ((*d) == "." || (*d) == "..") {
continue;
}
#ifdef QT_DEBUG
std::cout<< "copyDir dir name " <<(*d).toStdString() << std::endl;
#endif
if (!QFileInfo(directory.path() + "/" + (*d)).isDir()) {
files << (*d);
continue;
}
QDir temp(destination + "/" + (*d));
temp.mkpath(temp.path());
if (!copyDir(directory.path() + "/" + (*d), destination + "/" + (*d), override)) {
#ifdef QT_DEBUG
std::cout << "copyDir err: "<< (directory.path() + "/" + (*d), destination + "/" + (*d)).toStdString() << std::endl;
#endif
error = true;
}
}
for (f = files.begin(); f != files.end(); ++f) {
QFile tempFile(directory.path() + "/" + (*f));
QFile destFile(destination + "/" + directory.relativeFilePath(tempFile.fileName()));
if (destFile.exists() && override) {
destFile.remove();
}
if (!tempFile.copy(destination + "/" + directory.relativeFilePath(tempFile.fileName()))) {
#ifdef QT_DEBUG
std::cout << "copyDir /copy file/ err: "<< (destination + "/" + directory.relativeFilePath(tempFile.fileName())).toStdString() << std::endl;
#endif
error = true;
}
}
return !error;
}
|
This post has been edited 2 times, last edit by "thec0der" (Mar 24th 2009, 5:19pm)
This post has been edited 1 times, last edit by "thec0der" (Mar 24th 2009, 11:25am)
|
|
Source code |
1 |
copyDir dir name .htaccess |