From e1e75a4fad1c2d006b812c2728fe3e9ad6101869 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 11 May 2017 07:45:55 +0200 Subject: [PATCH] #1476 Add helper method fileExists() which includes isFile() --- Fwk/AppFwk/CommonCode/cafUtils.cpp | 18 ++++++++++++++++++ Fwk/AppFwk/CommonCode/cafUtils.h | 2 ++ 2 files changed, 20 insertions(+) diff --git a/Fwk/AppFwk/CommonCode/cafUtils.cpp b/Fwk/AppFwk/CommonCode/cafUtils.cpp index f8fb68f254..679170b94b 100644 --- a/Fwk/AppFwk/CommonCode/cafUtils.cpp +++ b/Fwk/AppFwk/CommonCode/cafUtils.cpp @@ -223,4 +223,22 @@ bool Utils::getSaveDirectoryAndCheckOverwriteFiles(const QString& defaultDir, st } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool Utils::fileExists(const QString& fileName) +{ + QFileInfo fi(fileName); + + // QFileInfo::exists returns true for both files and folders + // Also check if the path points to a file + + if (fi.exists() && fi.isFile()) + { + return true; + } + + return false; +} + } // namespace caf diff --git a/Fwk/AppFwk/CommonCode/cafUtils.h b/Fwk/AppFwk/CommonCode/cafUtils.h index 8cbdde125c..cb92cee651 100644 --- a/Fwk/AppFwk/CommonCode/cafUtils.h +++ b/Fwk/AppFwk/CommonCode/cafUtils.h @@ -63,6 +63,8 @@ public: static QString indentString(int numSpacesToIndent, const QString& str); static bool getSaveDirectoryAndCheckOverwriteFiles(const QString& defaultDir, std::vector fileNames, QString* saveDir); + + static bool fileExists(const QString& fileName); }; }