16 #include <QTextStream> 23 bool copyRecursively(QString sourceDir, QString destinationDir,
bool overWriteDirectory)
25 QDir originDirectory(sourceDir);
27 if (! originDirectory.exists())
32 QDir destinationDirectory(destinationDir);
34 if(destinationDirectory.exists() && !overWriteDirectory)
38 else if(destinationDirectory.exists() && overWriteDirectory)
40 destinationDirectory.removeRecursively();
43 originDirectory.mkpath(destinationDir);
45 foreach (QString directoryName, originDirectory.entryList(QDir::Dirs | \
46 QDir::NoDotAndDotDot))
48 QString destinationPath = destinationDir +
"/" + directoryName;
49 originDirectory.mkpath(destinationPath);
50 copyRecursively(sourceDir +
"/" + directoryName, destinationPath, overWriteDirectory);
53 foreach (QString fileName, originDirectory.entryList(QDir::Files))
55 QFile::copy(sourceDir +
"/" + fileName, destinationDir +
"/" + fileName);
59 QDir finalDestination(destinationDir);
60 finalDestination.refresh();
62 if(finalDestination.exists())
75 if (dir.exists(dirName)) {
76 Q_FOREACH(QFileInfo info, dir.entryInfoList(QDir::NoDotAndDotDot | QDir::System | QDir::Hidden | QDir::AllDirs | QDir::Files, QDir::DirsFirst)) {
81 result = QFile::remove(info.absoluteFilePath());
88 result = dir.rmdir(dirName);
96 dir.setFilter(QDir::AllDirs|QDir::NoDotAndDotDot);
97 QFileInfoList retval = dir.entryInfoList();
105 dir.setFilter(QDir::Files);
106 dir.setNameFilters(nameFilters);
108 foreach(QFileInfo file, dir.entryInfoList())
109 retval << file.absoluteFilePath();
112 foreach(QFileInfo directory,
getDirs(path))
125 QFile the_file(path);
126 the_file.open(QFile::ReadWrite);
127 QByteArray all = the_file.readAll();
128 if(!all.endsWith(
"\n"))
130 CX_LOG_WARNING() <<
"File does not end with whitespace, adding newline to the file: " << path;
131 QTextStream out(&the_file);
bool removeNonemptyDirRecursively(const QString &dirName)
bool copyRecursively(QString sourceDir, QString destinationDir, bool overWriteDirectory)
QFileInfoList getDirs(QString path)
QStringList getAbsolutePathToXmlFiles(QString path, bool includeSubDirs)
QStringList getAbsolutePathToFiles(QString path, QStringList nameFilters, bool includeSubDirs)
void forceNewlineBeforeEof(QString path)
Namespace for all CustusX production code.