-
Notifications
You must be signed in to change notification settings - Fork 1
/
WinFile.cpp
62 lines (59 loc) · 1.43 KB
/
WinFile.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
#include <windows.h>
#include "WinFile.h"
WinFile::WinFile(string dir)
{
currentFilePos=0;
m_strDir=dir;
if(!isFolder(dir))
throw IOException("'"+dir+"'²»ÊÇĿ¼.");
open(dir);
}
//¶ÁÈ¡
bool WinFile::open(string strFolder)//c:\win\sys sys
{
bool isFind=false;
string path,name;
if ( strFolder.length()==0)
return false;
HANDLE hFind = NULL;
WIN32_FIND_DATA data;
strFolder += "\\*";
hFind = FindFirstFile(strFolder.c_str(),&data);
if(hFind == INVALID_HANDLE_VALUE)
return false;
while ( hFind != INVALID_HANDLE_VALUE )//²éÕҳɹ¦
{
if ( ( strcmp( data.cFileName, "." ) == 0 ) || (strcmp(data.cFileName, ".." ) == 0 ) )
{
if ( ! FindNextFile( hFind, &data ) )
break;
else
continue;
}
isFind=true;
name=data.cFileName;
fileNames.push_back(name);
if (!FindNextFile(hFind,&data ))
break;
}
return isFind;
}
bool WinFile::isFolder(string name)
{
WIN32_FIND_DATA wfd;
bool isFolder = false;
HANDLE hFile=FindFirstFile(name.c_str(),&wfd);
if ((hFile != INVALID_HANDLE_VALUE) && (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
isFolder=true;
}
FindClose(hFile);
return isFolder;
}
bool WinFile::getNextFileName(string& name)
{
if(currentFilePos>=fileNames.size())
return false;
name=fileNames[currentFilePos++];
return name.length()>0;
}