-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathFileUtility.cpp
105 lines (89 loc) · 2.26 KB
/
FileUtility.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include "StdAfx.h"
#include <io.h>
#include <windows.h>
#include <commdlg.h>
#include <direct.h>
#include "FileUtility.h"
#include "StringUtility.h"
#include "MemoryCheck.h"
namespace Scan
{
String getAppFullName()
{
char buf[MAX_PATH] = "";
GetModuleFileName(NULL, buf, sizeof(buf));
return buf;
}
String getAppName()
{
char buf[MAX_PATH] = "";
GetFileTitle(getAppFullName().c_str(), buf, sizeof(buf));
if (char* p = strrchr(buf, '.'))
{
*p = 0;
}
return buf;
}
void splitFileFullName(const String& fullName,
String& driver,
String& dir,
String& title,
String& ext)
{
char sDriver[8] = "";
char sDir[MAX_PATH] = "";
char sTitle[MAX_PATH] = "";
char sExt[16] = "";
_splitpath_s(
fullName.c_str(),
sDriver,
sDir,
sTitle,
sExt);
driver = sDriver;
dir = sDir;
title = sTitle;
ext = sExt;
}
bool isFileExist(const String& name)
{
return _access(name.c_str(), 0) == 0;
}
bool deleteFile(const String& name)
{
return DeleteFile(name.c_str()) == TRUE;
}
bool deleteDirectory(const String& name)
{
return RemoveDirectory(name.c_str()) == TRUE;
}
bool copyFile(const String& newName, const String& oldName)
{
return CopyFile(oldName.c_str(), newName.c_str(), FALSE) == TRUE;
}
bool createDirectory(const String& name, bool recursive/* = true*/)
{
if (!recursive)
{
_mkdir(name.c_str());
return true;
}
String driver, path, file, ext;
splitFileFullName(name, driver, path, file, ext);
StringVector v;
StringUtil::split(v, path, "/\\");
String validDir = driver;
StringVector::iterator iter = v.begin();
while (iter != v.end())
{
validDir += validDir.empty() ? "" : "/";
validDir += *iter;
_mkdir(validDir.c_str());
++iter;
}
validDir += validDir.empty() ? "" : "/" ;
validDir += file;
_mkdir(validDir.c_str());
return true;
}
}