-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIOfunctions.cpp
130 lines (97 loc) · 2.77 KB
/
IOfunctions.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include "IOfunction.h"
using namespace std;
int IOfunction::FolderMap(
String folderPath,
void* ptrToPassInFunction,
void(*function)(String path, String fileName, unsigned long long lastModifiedDate, unsigned long long fileSize, bool isDirectory, void* ptr)
)
{
WIN32_FIND_DATA file_data;
HANDLE Win_DirHandle = FindFirstFile(String(folderPath + L"\\*").c_str(), &file_data);
if (Win_DirHandle == INVALID_HANDLE_VALUE)
// Folder is empty
return 1;
if (file_data.cFileName[0] == '.')
FindNextFile(Win_DirHandle, &file_data);
if (file_data.cFileName[0] == '.' && file_data.cFileName[1] == '.')
{
if (FindNextFile(Win_DirHandle, &file_data) == 0)
{
// Folder is empty
FindClose(Win_DirHandle);
return 1;
}
}
do{
ULARGE_INTEGER convertDate;
convertDate.LowPart = file_data.ftLastWriteTime.dwLowDateTime;
convertDate.HighPart = file_data.ftLastWriteTime.dwHighDateTime;
ULARGE_INTEGER convertSize;
convertSize.LowPart = file_data.nFileSizeLow;
convertSize.HighPart = file_data.nFileSizeHigh;
(*function)(
folderPath,
String(file_data.cFileName),
(unsigned long long)convertDate.QuadPart,
(unsigned long long)convertSize.QuadPart,
(file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0,
ptrToPassInFunction
);
} while (FindNextFile(Win_DirHandle, &file_data) != 0);
// Close the directory
if (FindClose(Win_DirHandle) != 0)
{
return 0;
}
return 0;
}
void IOfunction::CreateDirectoryByPath(String originalPath, String destinationPath)
{
SystemWraper::SysCreateDirectory(originalPath, destinationPath);
}
void IOfunction::DeleteFileByPath(String fileName)
{
SystemWraper::SysDeleteFile(fileName);
}
void IOfunction::DeleteFolderByPath(String path)
{
IOfunction::FolderMap(
path,
NULL,
[](String path, String fileName, unsigned long long lastModifiedDate, unsigned long long fileSize, bool isDirectory, void* ptr)
{
if (isDirectory)
{
IOfunction::DeleteFolderByPath(path + BACKSLASH + fileName);
}
else
{
IOfunction::DeleteFileByPath(path + BACKSLASH + fileName);
}
}
);
SystemWraper::SysRemoveDirectory(path);
}
void IOfunction::CopyFileByPath(String origin, String destination)
{
SystemWraper::SysCopyFile(origin, destination);
}
void IOfunction::CopyFolderByPath(String origin, String destination)
{
CreateDirectoryByPath(origin, destination);
IOfunction::FolderMap(
origin,
(void*)&destination,
[](String path, String fileName, unsigned long long lastModifiedDate, unsigned long long fileSize, bool isDirectory, void* ptr)
{
if (isDirectory)
{
IOfunction::CopyFolderByPath(path + BACKSLASH + fileName, *(String*)ptr + BACKSLASH + fileName);
}
else
{
IOfunction::CopyFileByPath(path + BACKSLASH + fileName, *(String*)ptr + BACKSLASH + fileName);
}
}
);
}