source: trunk/Include/Classes/System/IO/DirectoryInfo.ab@ 319

Last change on this file since 319 was 318, checked in by OverTaker, 17 years ago

DirectoryInfo.GetFileSystemInfos()中心に色々と...

File size: 4.3 KB
Line 
1Imports System.Collections.Generic
2
3Namespace System
4Namespace IO
5
6Class DirectoryInfo
7 Inherits FileSystemInfo
8Public
9 Sub DirectoryInfo(path As String)
10 OriginalPath = path
11 FullPath = Path.GetFullPath(path)
12 Refresh()
13 End Sub
14
15 Sub ~DirectoryInfo()
16 End Sub
17
18 'Public Property
19 Function Parent() As DirectoryInfo
20 Return New DirectoryInfo(Path.GetDirectoryName(FullPath))
21 End Function
22
23 Function Root() As DirectoryInfo
24 Return New DirectoryInfo(Path.GetPathRoot(FullPath))
25 End Function
26
27 'Public Method
28 Sub Create()
29 CreateDirectory(ToTCStr(FullPath), NULL)
30 End Sub
31
32/* Sub Create(directorySecurity As DirectorySecurity)
33 End Sub*/
34
35 Override Sub Delete()
36 RemoveDirectory(ToTCStr(FullPath))
37 End Sub
38
39 Sub Delete(recursive As Boolean)
40 If recursive Then
41 ' ディレクトリ内のすべての情報を削除する
42
43 Dim dirPath = FullPath As String
44
45 ' 終端の '\' を除去
46 If dirPath[dirPath.Length-1] = Asc("\") Then
47 dirPath = dirPath.Substring(0, dirPath.Length-1)
48 End If
49
50 ' double null-terminated にする
51 dirPath = dirPath + Chr$(0)
52
53 Dim op As SHFILEOPSTRUCT
54 op.hwnd = NULL
55 op.wFunc = FO_DELETE
56 op.pFrom = ToTCStr(dirPath)
57 op.pTo = NULL
58 op.fFlags = FOF_NOCONFIRMATION or FOF_NOERRORUI or FOF_SILENT
59
60 If SHFileOperation(op) <> 0 Then
61 ' TODO: エラー処理
62 debug
63 End If
64 Else
65 ' ディレクトリが空の場合は削除する
66 This.Delete()
67 End If
68 End Sub
69
70/* Function GetAccessControl() As DirectorySecurity
71 End Function*/
72
73/* Function GetAccessControl(includeSections As AccessControlSections) As DirectorySecurity
74 End Function*/
75
76 Function GetDirectories() As List<DirectoryInfo>
77 Return GetDirectories("?*")
78 End Function
79
80 Function GetDirectories(searchPattern As String) As List<DirectoryInfo>
81 Dim infos As List<FileSystemInfo>
82 infos = GetFileSystemInfos(searchPattern)
83
84 Dim dirs As List<DirectoryInfo>
85 Dim i As Long
86 For i = 0 To ELM(infos.Count)
87 If infos[i].GetType.ToString() = "DirectoryInfo" Then
88 dirs.Add(infos[i] As DirectoryInfo)
89 End If
90 Next
91 Return dirs
92 End Function
93
94/* Function GetDirectories(searchPattern As String, searchOption As SearchOption) As List<DirectoryInfo>
95 If searchOption = SearchOption.TopDirectoryOnly Then
96 Return GetDirectories(searchPattern)
97 Else
98 Dim dirs As List<DirectoryInfo>
99 dirs = GetDirectories(searchPattern)
100 Dim i As Long
101
102 End If
103 End Function*/
104
105 Function GetFiles() As List<FileInfo>
106 Return GetFiles("?*")
107 End Function
108
109 Function GetFiles(searchPattern As String) As List<FileInfo>
110 Dim infos As List<FileSystemInfo>
111 infos = GetFileSystemInfos(searchPattern)
112
113 Dim files As List<FileInfo>
114 Dim i As Long
115 For i = 0 To ELM(infos.Count)
116 If infos[i].GetType.ToString() = "FileInfo" Then
117 files.Add(infos[i] As FileInfo)
118 End If
119 Next
120 Return files
121 End Function
122
123/* Function GetFiles(searchPattern As String, searchOption As SearchOption) As List<FileInfo>
124 End Function*/
125
126 Function GetFileSystemInfos() As List<FileSystemInfo>
127 Return GetFileSystemInfos("?*")
128 End Function
129
130 Function GetFileSystemInfos(searchPattern As String) As List<FileSystemInfo>
131 Dim find As HANDLE
132 Dim findData As WIN32_FIND_DATA
133 find = FindFirstFile(ToTCStr(Path.Combine(FullPath, searchPattern)), findData)
134 If find = INVALID_HANDLE_VALUE Then
135 debug 'Exception
136 Return Nothing
137 End If
138
139 Dim files As List<FileSystemInfo>
140 Dim lastError = GetLastError() As DWord
141 Dim i As Long
142 While lastError <> ERROR_NO_MORE_FILES
143 If i > 1 Then
144 Dim s = New String(findData.cFileName As PCTSTR)
145 If (findData.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY) = FILE_ATTRIBUTE_DIRECTORY Then
146 files.Add(New DirectoryInfo(Path.Combine(FullPath, s)))
147 Else
148 files.Add(New FileInfo(Path.Combine(FullPath, s)))
149 End If
150 End If
151
152 If FindNextFile(find, findData) = False Then
153 lastError = GetLastError()
154 If lastError <> ERROR_NO_MORE_FILES Then
155 debug 'Exception
156 Return Nothing
157 End If
158 End If
159 i++
160 Wend
161 Return files
162 End Function
163
164 Sub MoveTo(destDirName As String)
165 If MoveFile(ToTCStr(FullPath), ToTCStr(destDirName)) = FALSE Then
166 'Exception
167 End If
168 End Sub
169
170/* Sub SetAccessControl(directorySecurity As DirectorySecurity)
171 End Sub*/
172
173End Class
174
175End Namespace
176End Namespace
Note: See TracBrowser for help on using the repository browser.