37 #include <QTextStream> 44 bool copyRecursively(QString sourceDir, QString destinationDir,
bool overWriteDirectory)
46 QDir originDirectory(sourceDir);
48 if (! originDirectory.exists())
53 QDir destinationDirectory(destinationDir);
55 if(destinationDirectory.exists() && !overWriteDirectory)
59 else if(destinationDirectory.exists() && overWriteDirectory)
61 destinationDirectory.removeRecursively();
64 originDirectory.mkpath(destinationDir);
66 foreach (QString directoryName, originDirectory.entryList(QDir::Dirs | \
67 QDir::NoDotAndDotDot))
69 QString destinationPath = destinationDir +
"/" + directoryName;
70 originDirectory.mkpath(destinationPath);
71 copyRecursively(sourceDir +
"/" + directoryName, destinationPath, overWriteDirectory);
74 foreach (QString fileName, originDirectory.entryList(QDir::Files))
76 QFile::copy(sourceDir +
"/" + fileName, destinationDir +
"/" + fileName);
80 QDir finalDestination(destinationDir);
81 finalDestination.refresh();
83 if(finalDestination.exists())
96 if (dir.exists(dirName)) {
97 Q_FOREACH(QFileInfo info, dir.entryInfoList(QDir::NoDotAndDotDot | QDir::System | QDir::Hidden | QDir::AllDirs | QDir::Files, QDir::DirsFirst)) {
102 result = QFile::remove(info.absoluteFilePath());
109 result = dir.rmdir(dirName);
117 dir.setFilter(QDir::AllDirs|QDir::NoDotAndDotDot);
118 QFileInfoList retval = dir.entryInfoList();
126 dir.setFilter(QDir::Files);
127 dir.setNameFilters(nameFilters);
129 foreach(QFileInfo file, dir.entryInfoList())
130 retval << file.absoluteFilePath();
133 foreach(QFileInfo directory,
getDirs(path))
146 QFile the_file(path);
147 the_file.open(QFile::ReadWrite);
148 QByteArray all = the_file.readAll();
149 if(!all.endsWith(
"\n"))
151 CX_LOG_WARNING() <<
"File does not end with whitespace, adding newline to the file: " << path;
152 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.