Check if path to csv file is valid @input: - filePath - string with absolute path to file - mustExist - True if file must exist, False if this is not important @output: - bool - True if file is OK, else False
| 13 | // @output: |
| 14 | // - bool - True if file is OK, else False |
| 15 | inline bool CheckFile(const QString& filePath, const bool mustExist = false) |
| 16 | { |
| 17 | if (filePath.isEmpty()) { |
| 18 | qDebug() << __FUNCTION__ << "Error - file path is empty"; |
| 19 | return false; |
| 20 | } |
| 21 | |
| 22 | QFileInfo fileInfo(filePath); |
| 23 | if (fileInfo.isAbsolute() && false == fileInfo.isDir()) { |
| 24 | if (mustExist && false == fileInfo.exists()) { return false; } |
| 25 | if ("csv" != fileInfo.suffix()) { |
| 26 | qDebug() << __FUNCTION__ << |
| 27 | "Warning - file suffix is not .csv"; |
| 28 | } |
| 29 | |
| 30 | return true; |
| 31 | } |
| 32 | |
| 33 | return false; |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | #endif // QTCSVFILECHECKER_H |