forked from javeme/cpp2java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWinFile.java
More file actions
97 lines (67 loc) · 1.53 KB
/
WinFile.java
File metadata and controls
97 lines (67 loc) · 1.53 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
public class WinFile:public File
{
//public WinFile(String dir);
private String m_strDir;
private ArrayList<String> fileNames;
private int currentFilePos;
//public boolean open(String strFolder);
//public boolean isFolder(String name);
//public boolean getNextFileName(String name);
WinFile(String dir)
{
currentFilePos=0;
m_strDir=dir;
if(!isFolder(dir))
throw IOException("'"+dir+"'²»ÊÇĿ¼.");
open(dir);
}
//¶ÁÈ¡
boolean open(String strFolder)//c:\win\sys sys
{
boolean 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;
}
boolean isFolder(String name)
{
WIN32_FIND_DATA wfd;
boolean 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;
}
boolean getNextFileName(String name)
{
if(currentFilePos>=fileNames.size())
return false;
name=fileNames[currentFilePos++];
return name.length()>0;
}
}