-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsystem.cpp
More file actions
128 lines (119 loc) · 4.72 KB
/
system.cpp
File metadata and controls
128 lines (119 loc) · 4.72 KB
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
//****************************************************************************************************
//ïîäêëþ÷àåìûå áèáëèîòåêè
//****************************************************************************************************
#include "system.h"
#include <string.h>
#include <windows.h>
//****************************************************************************************************
//ðåàëèçàöèÿ ôóíêöèé
//****************************************************************************************************
//----------------------------------------------------------------------------------------------------
//ñîçäàòü ñïèñîê ôàéëîâ äèðåêòîðèè
//----------------------------------------------------------------------------------------------------
void CreateFileList(const std::string &path,std::vector<std::string> &vector_file_name,std::vector<std::string> &vector_file_name_without_path)
{
vector_file_name.clear();
vector_file_name_without_path.clear();
char current_directory[MAX_PATH];
if (GetCurrentDirectory(MAX_PATH,current_directory)==FALSE) return;
if (SetCurrentDirectory(path.c_str())==FALSE) return;
WIN32_FIND_DATA wfd;
HANDLE handle=FindFirstFile("*",&wfd);
if (handle==INVALID_HANDLE_VALUE)
{
SetCurrentDirectory(current_directory);
return;
}
while(true)
{
if (wfd.cFileName[0]!='.' && !(wfd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))//åñëè ýòî ôàéë
{
//äîáàâëÿåì ôàéë â ñïèñîê
std::string file_name=path;
file_name+=GetPathDivider();
file_name+=wfd.cFileName;
vector_file_name.push_back(file_name);
vector_file_name_without_path.push_back(wfd.cFileName);
}
if (FindNextFile(handle,&wfd)==FALSE) break;
}
FindClose(handle);
SetCurrentDirectory(current_directory);
}
//----------------------------------------------------------------------------------------------------
//ñîçäàòü ñïèñîê êàòàëîãîâ äèðåêòîðèè
//----------------------------------------------------------------------------------------------------
void CreateDirectoryList(const std::string &path,std::vector<std::string> &vector_directory_name)
{
vector_directory_name.clear();
char current_directory[MAX_PATH];
if (GetCurrentDirectory(MAX_PATH,current_directory)==FALSE) return;
if (SetCurrentDirectory(path.c_str())==FALSE) return;
WIN32_FIND_DATA wfd;
HANDLE handle=FindFirstFile("*",&wfd);
if (handle==INVALID_HANDLE_VALUE)
{
SetCurrentDirectory(current_directory);
return;
}
while(true)
{
if (wfd.cFileName[0]!='.' && (wfd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))//åñëè ýòî äèðåêòîðèÿ
{
std::string new_path=path;
new_path+=GetPathDivider();
new_path+=wfd.cFileName;
vector_directory_name.push_back(new_path);
}
if (FindNextFile(handle,&wfd)==FALSE) break;
}
FindClose(handle);
SetCurrentDirectory(current_directory);
}
//----------------------------------------------------------------------------------------------------
//ñîçäàòü êàòàëîã
//----------------------------------------------------------------------------------------------------
void MakeDirectory(const std::string &directory_name)
{
CreateDirectory(directory_name.c_str(),NULL);
}
//----------------------------------------------------------------------------------------------------
//ïîëó÷èòü ïðîøåäøåå âðåìÿ â ñåêóíäàõ
//----------------------------------------------------------------------------------------------------
long double GetSecondCounter(void)
{
return(GetTickCount()/1000.0);
}
//----------------------------------------------------------------------------------------------------
//ïàóçà â ìèëëèñåêóíäàõ
//----------------------------------------------------------------------------------------------------
void PauseInMs(size_t ms)
{
HANDLE hEvent=CreateEvent(NULL,TRUE,FALSE,NULL);
ResetEvent(hEvent);
WaitForSingleObject(hEvent,ms);
CloseHandle(hEvent);
}
//----------------------------------------------------------------------------------------------------
//ïîëó÷èòü òåêóùóþ äèðåêòîðèþ
//----------------------------------------------------------------------------------------------------
std::string GetCurrentPath(void)
{
char path[MAX_PATH];
GetCurrentDirectory(MAX_PATH,path);
return(std::string(path));
}
//----------------------------------------------------------------------------------------------------
//ïîëó÷èòü ðàçäåëèòåëü êàòàëîãî
//----------------------------------------------------------------------------------------------------
std::string GetPathDivider(void)
{
return(std::string("\\"));
}
//----------------------------------------------------------------------------------------------------
//âûâåñòè ñîîáùåíèå
//----------------------------------------------------------------------------------------------------
void PutMessage(const std::string &message)
{
MessageBox(NULL,message.c_str(),"Ñîîáùåíèå",MB_OK);
}