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

Last change on this file since 330 was 330, checked in by dai, 17 years ago

コンストラクタパラメータを処理中にGCがかかると、初期化中オブジェクトのスキャンで強制終了してしまうバグを修正。
グローバル領域に保持されるオブジェクトの一部がGCによって不正に回収されてしまうバグを修正。
Thread.Nameプロパティを実装

File size: 5.0 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 Select Case searchOption
96 Case SearchOption.TopDirectoryOnly
97 Return GetDirectories(searchPattern)
98 Case SearchOption.AllDirectories
99 Dim dirs As List<DirectoryInfo>
100 dirs = GetDirectories(searchPattern)
101
102 Dim subdirs As List<DirectoryInfo>
103 Dim i As Long, j As Long
104 For i = 0 To ELM(dirs.Count)
105 subdirs = dirs[i].GetDirectories(searchPattern)
106 For j = 0 To ELM(subdirs.Count)
107 dirs.Add(subdirs[i])
108 Next
109 Next
110 Return dirs
111 End Select
112 End Function
113
114 Function GetFiles() As List<FileInfo>
115 Return GetFiles("?*")
116 End Function
117
118 Function GetFiles(searchPattern As String) As List<FileInfo>
119 Dim infos As List<FileSystemInfo>
120 infos = GetFileSystemInfos(searchPattern)
121
122 Dim files As List<FileInfo>
123 Dim i As Long
124 For i = 0 To ELM(infos.Count)
125 If infos[i].GetType.ToString() = "FileInfo" Then
126 files.Add(infos[i] As FileInfo)
127 End If
128 Next
129 Return files
130 End Function
131
132 Function GetFiles(searchPattern As String, searchOption As SearchOption) As List<FileInfo>
133 Select Case searchOption
134 Case SearchOption.TopDirectoryOnly
135 Return GetFiles(searchPattern)
136 Case SearchOption.AllDirectories
137 Dim dirs As List<DirectoryInfo>
138 dirs = GetDirectories(searchPattern, SearchOption.AllDirectories)
139
140 Dim files As List<FileInfo>
141 Dim subfiles As List<FileInfo>
142 Dim i As Long, j As Long
143 For i = 0 To ELM(dirs.Count)
144 subfiles = dirs[i].GetFiles(searchPattern)
145 For j = 0 To ELM(subfiles.Count)
146 files.Add(subfiles[j])
147 Next
148 Next
149 Return files
150 End Select
151 End Function
152
153 Function GetFileSystemInfos() As List<FileSystemInfo>
154 Return GetFileSystemInfos("?*")
155 End Function
156
157 Function GetFileSystemInfos(searchPattern As String) As List<FileSystemInfo>
158 Dim find As HANDLE
159 Dim findData As WIN32_FIND_DATA
160 find = FindFirstFile(ToTCStr(Path.Combine(FullPath, searchPattern)), findData)
161 If find = INVALID_HANDLE_VALUE Then
162 debug 'Exception
163 Return Nothing
164 End If
165
166 Dim files As List<FileSystemInfo>
167 Dim i = 0 As Long
168 Do
169 If i > 1 Then
170 Dim s = New String(findData.cFileName As PCTSTR)
171 If (findData.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY) = FILE_ATTRIBUTE_DIRECTORY Then
172 files.Add(New DirectoryInfo(Path.Combine(FullPath, s)))
173 Else
174 files.Add(New FileInfo(Path.Combine(FullPath, s)))
175 End If
176 End If
177 i++
178 Loop While FindNextFile(find, findData)
179 FindClose(find)
180
181 If GetLastError() = ERROR_NO_MORE_FILES Then
182 Return files
183 Else
184 debug 'Exception
185 Return Nothing
186 End If
187 End Function
188
189 Sub MoveTo(destDirName As String)
190 If MoveFile(ToTCStr(FullPath), ToTCStr(destDirName)) = FALSE Then
191 'Exception
192 End If
193 End Sub
194
195/* Sub SetAccessControl(directorySecurity As DirectorySecurity)
196 End Sub*/
197
198End Class
199
200End Namespace
201End Namespace
Note: See TracBrowser for help on using the repository browser.