This repository has been archived by the owner on Aug 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
myfileinfo.cpp
63 lines (58 loc) · 1.94 KB
/
myfileinfo.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "myfileinfo.h"
#include <QRegularExpression>
QString MyFileInfo::dirPath(const QString &file)
{
QString processedFileName = file;
processedFileName.remove( QRegularExpression("^\"") );
processedFileName.remove( QRegularExpression("\"$") );
processedFileName.remove( QRegularExpression("\\$") );
processedFileName.remove( QRegularExpression("/$") );
if(!exists(processedFileName)) return QString("");
QFileInfo tmp(processedFileName);
if(tmp.isDir()) return tmp.absoluteFilePath();
else return tmp.absolutePath();
}
QString MyFileInfo::dirPath()
{
if( filePath().isEmpty() || !exists() ) return QString("");
if( isDir() ) return absoluteFilePath();
else return absolutePath();
}
int MyFileInfo::setValidFile(const QString &file)
/* return 0 if "file" doesn't exist
return 1 if "file" exist and is a file
return 2 if "file" exist but is not a file (likely a directory)
*/
{
QString processedFileName = file;
processedFileName.remove( QRegularExpression("^\"") );
processedFileName.remove( QRegularExpression("\"$") );
processedFileName.remove( QRegularExpression("\\$") );
processedFileName.remove( QRegularExpression("/$") );
if(exists(processedFileName)){
setFile(processedFileName);
if(isFile())
return 1;
else
return 2;
} else
return 0;
}
int MyFileInfo::checkValidFile(QString &file)
/* remove any starting/ending quotes and ending slash of "file"
return 0 if "file" doesn't exist
return 1 if "file" exist and is a file
return 2 if "file" exist but is not a file (likely a directory)*/
{
file.remove( QRegularExpression("^\"") );
file.remove( QRegularExpression("\"$") );
file.remove( QRegularExpression("\\$") );
file.remove( QRegularExpression("/$") );
if(exists(file)){
if(QFileInfo(file).isFile())
return 1;
else
return 2;
} else
return 0;
}