source: trunk/ab5.0/ablib/src/Classes/System/IO/Directory.ab@ 506

Last change on this file since 506 was 431, checked in by OverTaker, 16 years ago

メソッド名の間違い修整

File size: 10.2 KB
Line 
1Imports System.Collections.Generic
2
3Namespace System
4Namespace IO
5
6/*!
7@brief ディレクトリの情報を取得したり操作するクラス
8*/
9
10Class Directory
11Public
12
13 '----------------------------------------------------------------
14 ' パブリック メソッド
15 '----------------------------------------------------------------
16
17 /*!
18 @brief ディレクトリを作成する
19 @param 作成するディレクトリのファイルパス
20 @return 作成されたディレクトリのDirctoryInfo
21 */
22 Static Function CreateDirectory(path As String) As DirectoryInfo
23 Dim info = New DirectoryInfo(path)
24 info.Create()
25 Return info
26 End Function
27
28 /*
29 Static Function CreateDirectory(path As String, directorySecurity As DirectorySecurity) As DirectoryInfo
30 End Function */
31
32 /*!
33 @brief ディレクトリを削除する
34 ディレクトリが開き出ない場合は削除されない
35 @param 消去するディレクトリのファイルパス
36 */
37 Static Sub Delete(path As String)
38 Dim info = New DirectoryInfo(path)
39 info.Delete()
40 End Sub
41
42 /*!
43 @brief ディレクトリを削除する
44 @param 削除するディレクトリのファイルパス
45 @param ディレクトリの中身も消去する場合True
46 */
47 Static Sub Delete(path As String, recursive As Boolean)
48 Dim info = New DirectoryInfo(path)
49 info.Delete(recursive)
50 End Sub
51
52 /*!
53 @brief ディレクトリが存在するかどうか
54 @param 調べるディレクトリのファイルパス
55 @retval True 存在する
56 @retval False 存在しない
57 */
58 Static Function Exists(path As String) As Boolean
59 Dim info = New DirectoryInfo(path)
60 Return info.Exists
61 End Function
62
63 /*!
64 @brief カレントディレクトリを取得する
65 @return カレントディレクトリを示すパス
66 */
67 Static Function GetCurrentDirectory() As String
68 Return System.Environment.CurrentDirectory
69 End Function
70
71 /*
72 Static Function GetAccessControl(path As String) As DirectorySecurity
73 End Function
74
75 Static Function GetAccessControl(path As String, includeSections As System.Security.AccessControl.AccessControlSections) As DirectorySecurity
76 End Function
77 */
78
79 /*!
80 @brief ディレクトリの作成日を取得する
81 @param ディレクトリを示すパス
82 @return 作成日
83 */
84 Static Function GetCreationTime(path As String) As DateTime
85 Dim info = New DirectoryInfo(path)
86 Return info.CreationTime
87 End Function
88
89 /*!
90 @brief ディレクトリの作成日をUTC時刻で取得する
91 @param ディレクトリを示すパス
92 @return 作成日(UTC)
93 */
94 Static Function GetCreationTimeUtc(path As String) As DateTime
95 Dim info = New DirectoryInfo(path)
96 Return info.CreationTimeUtc
97 End Function
98
99 /*!
100 @brief ディレクトリ内のディレクトリを列挙する
101 @param 中身を調べるディレクトリのパス
102 @return ディレクトリのパス文字列が列挙された配列
103 */
104 Static Function GetDirectories(path As String) As List<String>
105 Return GetDirectories(path, "?*", SearchOption.TopDirectoryOnly)
106 End Function
107
108 /*!
109 @brief ディレクトリ内のディレクトリを列挙する
110 @param 中身を調べるディレクトリのパス
111 @param サーチするディレクトリ名のパターン
112 @return ディレクトリのパス文字列が列挙された配列
113 */
114 Static Function GetDirectories(path As String, searchPattern As String) As List<String>
115 Return GetDirectories(path, searchPattern, SearchOption.TopDirectoryOnly)
116 End Function
117
118 /*!
119 @brief ディレクトリ内のディレクトリを列挙する
120 @param 中身を調べるディレクトリのパス
121 @param サーチするディレクトリ名のパターン
122 @param サーチする範囲
123 @return ディレクトリのパス文字列が列挙された配列
124 */
125 Static Function GetDirectories(path As String, searchPattern As String, searchOption As SearchOption) As List<String>
126 Dim info = New DirectoryInfo(path)
127 Dim infos = info.GetDirectories(searchPattern, searchOption) As List<DirectoryInfo>
128 Dim enumerator = infos.GetEnumerator()
129 Dim list As List<String>
130 While enumerator.MoveNext()
131 list.Add(enumerator.Current.ToString)
132 Wend
133 Return list
134 End Function
135
136 /*!
137 @brief ディレクトリのルートディレクトリを取得する
138 @param ディレクトリのパス
139 @return ルートディレクトリ
140 */
141 Static Function GetDirectoryRoot(path As String) As String
142 Return Path.GetPathRoot(path)
143 End Function
144
145 /*!
146 @brief ディレクトリ内のファイルを列挙する
147 @param 中身を調べるディレクトリのパス
148 @return ファイルのパス文字列が列挙された配列
149 */
150 Static Function GetFiles(path As String) As List<String>
151 Return GetFiles(path, "?*", SearchOption.TopDirectoryOnly)
152 End Function
153
154 /*!
155 @brief ディレクトリ内のファイルを列挙する
156 @param 中身を調べるディレクトリのパス
157 @param サーチするファイル名のパターン
158 @return ファイルのパス文字列が列挙された配列
159 */
160 Static Function GetFiles(path As String, searchPattern As String) As List<String>
161 Return GetFiles(path, searchPattern, SearchOption.TopDirectoryOnly)
162 End Function
163
164 /*!
165 @brief ディレクトリ内のファイルを列挙する
166 @param 中身を調べるディレクトリのパス
167 @param サーチするファイル名のパターン
168 @param サーチする範囲
169 @return ファイルのパス文字列が列挙された配列
170 */
171 Static Function GetFiles(path As String, searchPattern As String, searchOption As SearchOption) As List<String>
172 Dim info = New DirectoryInfo(path)
173 Dim infos = info.GetFiles(searchPattern, searchOption) As List<FileInfo>
174 Dim enumerator = infos.GetEnumerator()
175 Dim list As List<String>
176 While enumerator.MoveNext()
177 list.Add(enumerator.Current.ToString)
178 Wend
179 Return list
180 End Function
181
182 /*!
183 @brief ディレクトリ内を列挙する
184 @param 中身を調べるディレクトリのパス
185 @return ファイルやディレクトリのパス文字列が列挙された配列
186 */
187 Static Function GetFileSystemEnties(path As String) As List<String>
188 Return GetFileSystemEnties(path, "?*")
189 End Function
190
191 /*!
192 @brief ディレクトリ内を列挙する
193 @param 中身を調べるディレクトリのパス
194 @param サーチするファイル名のパターン
195 @return ファイルやディレクトリのパス文字列が列挙された配列
196 */
197 Static Function GetFileSystemEnties(path As String, searchPattern As String) As List<String>
198 Dim info = New DirectoryInfo(path)
199 Dim infos = info.GetFileSystemInfos(searchPattern) As List<FileSystemInfo>
200 Dim enumerator = infos.GetEnumerator()
201 Dim list As List<String>
202 While enumerator.MoveNext()
203 list.Add(enumerator.Current.ToString)
204 Wend
205 Return list
206 End Function
207
208 /*!
209 @brief ディレクトリの最終アクセス日を取得する
210 @param ディレクトリのパス
211 @return 最終アクセス日
212 */
213 Static Function GetLastAccessTime(path As String) As DateTime
214 Dim info = New DirectoryInfo(path)
215 Return info.LastAccessTime
216 End Function
217
218 /*!
219 @brief ディレクトリの最終アクセス日をUTC時刻で取得する
220 @param ディレクトリのパス
221 @return 最終アクセス日(UTC)
222 */
223 Static Function GetLastAccessTimeUtc(path As String) As DateTime
224 Dim info = New DirectoryInfo(path)
225 Return info.LastAccessTimeUtc
226 End Function
227
228 /*!
229 @brief ディレクトリの最終書き込み日を取得する
230 @param ディレクトリのパス
231 @return 最終書き込み日
232 */
233 Static Function GetLastWriteTime(path As String) As DateTime
234 Dim info = New DirectoryInfo(path)
235 Return info.LastWriteTime
236 End Function
237
238 /*!
239 @brief ディレクトリの最終書き込み日をUTC時刻で取得する
240 @param ディレクトリのパス
241 @return 最終書き込み日(UTC)
242 */
243 Static Function GetLastWriteTimeUtc(path As String) As DateTime
244 Dim info = New DirectoryInfo(path)
245 Return info.LastWriteTimeUtc
246 End Function
247
248 /*!
249 @brief 使用可能な論理ドライブを列挙する
250 @return 論理ドライブを列挙したパス文字列
251 */
252 Static Function GetLogicalDrives() As List<String>
253 Dim drives = WIN32API_GetLogicalDrives() As DWord
254 If drives <> 0 Then
255 Dim list As List<String>
256 Dim i As SByte
257 For i = 0 To 25
258 If (drives and (1 << i)) <> 0 Then
259 list.Add(Chr$(Asc("A") + i) + ":\")
260 End If
261 Next
262 Return list
263 Else
264 Throw New IOException("Directory.GetLogicalDrives: Failed to GetLogicalDirives.")
265 End If
266 End Function
267
268 /*!
269 @brief ディレクトリのひとつ上のディレクトリを取得する
270 @param ディレクトリのパス
271 @return ひとつ上のディレクトリ
272 */
273 Static Function GetParent(path As String) As DirectoryInfo
274 Return New DirectoryInfo(Path.GetDirectoryName(path))
275 End Function
276
277 /*!
278 @brief ディレクトリを移動する
279 @param 移動元のディレクトリのパス
280 @param 移動後のディレクトリのパス
281 */
282 Static Sub Move(sourceDirName As String, destDirName As String)
283 Dim info = New DirectoryInfo(sourceDirName)
284 info.MoveTo(destDirName)
285 End Sub
286
287 /*
288 Static Sub SetAccessControl(path As String, directorySecurity As DirectorySecurity)
289 End Sub
290 */
291
292 /*!
293 @brief ディレクトリの作成日を設定する
294 @param ディレクトリのパス
295 @param 作成日
296 */
297 Static Sub SetCreationTime(path As String, creationTime As DateTime)
298 Dim info = New DirectoryInfo(path)
299 info.CreationTime = creationTime
300 End Sub
301
302 /*!
303 @brief ディレクトリの作成日をUTC時刻で設定する
304 @param ディレクトリのパス
305 @param 作成日(UTC)
306 */
307 Static Sub SetCreationTimeUtc(path As String, creationTime As DateTime)
308 Dim info = New DirectoryInfo(path)
309 info.CreationTimeUtc = creationTime
310 End Sub
311
312 /*!
313 @brief カレントディレクトリを設定する
314 @param ディレクトリのパス
315 */
316 Static Sub SetCurrentDirectory(path As String)
317 System.Environment.CurrentDirectory = path
318 End Sub
319
320 /*!
321 @brief ディレクトリの最終アクセス日を設定する
322 @param ディレクトリのパス
323 @param 最終アクセス日
324 */
325 Static Sub SetLastAccessTime(path As String, lastAccessTime As DateTime)
326 Dim info = New DirectoryInfo(path)
327 info.LastAccessTime = lastAccessTime
328 End Sub
329
330 /*!
331 @brief ディレクトリの最終アクセス日をUTC時刻で設定する
332 @param ディレクトリのパス
333 @param 最終アクセス日(UTC)
334 */
335 Static Sub SetLastAccessTimeUtc(path As String, lastAccessTime As DateTime)
336 Dim info = New DirectoryInfo(path)
337 info.LastAccessTimeUtc = lastAccessTime
338 End Sub
339
340 /*!
341 @brief ディレクトリの最終書き込み日を設定する
342 @param ディレクトリのパス
343 @param 最終書き込み日
344 */
345 Static Sub SetLastWriteTime(path As String, lastWriteTime As DateTime)
346 Dim info = New DirectoryInfo(path)
347 info.LastWriteTime = lastWriteTime
348 End Sub
349
350 /*!
351 @brief ディレクトリの最終書き込み日をUTC時刻で設定する
352 @param ディレクトリのパス
353 @param 最終書き込み日(UTC)
354 */
355 Static Sub SetLastWriteTimeUtc(path As String, lastWriteTime As DateTime)
356 Dim info = New DirectoryInfo(path)
357 info.LastWriteTimeUtc = lastWriteTime
358 End Sub
359End Class
360
361/* 名前が被ってメソッドから呼び出せない */
362Function WIN32API_GetLogicalDrives() As DWord
363 Return GetLogicalDrives()
364End Function
365
366End Namespace
367End Namespace
Note: See TracBrowser for help on using the repository browser.