Check if directory exists
Unsolved
General and Desktop
-
Hi @RIVOPICO,
I typically do something like:
const QFileInfo outputDir("some-directory-path-name"); if ((!outputDir.exists()) || (!outputDir.isDir()) || (!outputDir.isWritable())) { qWarning() << "output directory does not exist, is not a directory, or is not writeable" << outputDir.absoluteFilePath(); return false; }
Cheers.
-
Have a look at http://doc.qt.io/qt-5/qdir.html. Just like @koahnig said,
bool QDir::exists(const QString &name) const
andbool QDir::exists() const
do different things. -
You can try this..
QString destPath; QString srcPath; ...... ...... QDir dir(destPath); if(dir.exists()) { // append file name to destPath here .... destPath.append(fileName); if(!QFile::copy(srcPath, destPath)) { qDebug() << "Unable to copy file!"; .... } ... copy successful... }
Note that, for QFile::copy to work the destination path should contain the name of the file as well.
eg,QFile::copy("C:/work/myfolder/srcFile.txt", "D:/samples/destFile.txt");
will work.
QFile::copy("C:/work/myfolder/srcFile.txt", "D:/samples");
won't work.