source: trunk/ab5.0/ablib/src/Classes/System/IO/FileInfo.ab@ 523

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

タイプミスとか修整

File size: 5.6 KB
RevLine 
[271]1Namespace System
2Namespace IO
[60]3
[482]4/*
5@brief ファイルの情報取得,操作をするクラス
6@date 2008/03/14
7@author OverTaker
8*/
[271]9
[60]10Class FileInfo
[318]11 Inherits FileSystemInfo
12Public
[482]13 /*
14 @brief コンストラクタ
15 @param ファイルパス
16 */
[318]17 Sub FileInfo(path As String)
18 OriginalPath = path
19 FullPath = Path.GetFullPath(path)
20 End Sub
21
22 '----------------------------------------------------------------
[466]23 ' パブリック プロパティ
[318]24 '----------------------------------------------------------------
25
[482]26 /*
[523]27 @brief ひとつ上のフォルダを取得する
[482]28 @return フォルダを表すDirectoryInfo
29 */
[318]30 Function Directory() As DirectoryInfo
31 Return New DirectoryInfo(Path.GetDirectoryName(FullPath))
32 End Function
33
[482]34 /*
35 @brief ひとつ上のフォルダ名を取得する
36 @return フォルダを表すファイルパス
37 */
[318]38 Function DirectoryName() As String
39 Return Path.GetDirectoryName(FullPath)
40 End Function
41
[482]42 /*
43 @brief ファイルが読み取り専用かどうかを取得する
44 @retval True 読み取り専用ファイル
45 @retval False 読み取り専用ファイルではない
46 */
[318]47 Function IsReadOnly() As Boolean
[406]48 If (Attributes and FileAttributes.ReadOnly) = FileAttributes.ReadOnly Then
[318]49 Return True
50 Else
51 Return False
52 End If
53 End Function
[466]54
[482]55 /*
56 @brief ファイルサイズを取得する
57 @return ファイルサイズ
58 */
[466]59 Function Length() As QWord
60 Dim hFile = CreateFile(ToTCStr(FullPath), GENERIC_READ, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0)
61 If hFile = INVALID_HANDLE_VALUE Then
62 Throw New IOException("FileInfo.Length: Failed to CreateFile.")
63 Exit Function
64 End If
65
66 Dim length As QWord
67 If GetFileSizeEx(hFile, VarPtr(length)) Then
68 CloseHandle(hFile)
69 Return length
70 Else
71 CloseHandle(hFile)
72 Throw New IOException("FileInfo.Length: Failed to GetFileSize")
73 End If
74 End Function
75
76 '----------------------------------------------------------------
77 ' パブリック メソッド
78 '----------------------------------------------------------------
79
[482]80 /*
81 @brief ファイルにテキストを追加するストリームライターを作成する
82 @return ストリームライター
83 */
84 Function AppendText() As StreamWriter
85 Return File.AppendText(FullPath)
86 End Function
[466]87
[482]88 /*
89 @brief ファイルをコピーする(上書きしない)
90 @param コピー先のファイルパス
91 @return コピー先のファイルを表すFileInfo
92 */
[466]93 Function CopyTo(destFileName As String) As FileInfo
94 Return CopyTo(destFileName, False)
95 End Function
96
[482]97 /*
98 @brief ファイルをコピーする
99 @param コピー先のファイルパス
100 @param ファイルを上書きするかどうか
101 @return コピー先のファイルを表すFileInfo
102 */
[466]103 Function CopyTo(destFileName As String, overwrite As Boolean) As FileInfo
104 File.Copy(FullPath, destFileName, overwrite)
105 Return New FileInfo(destFileName)
106 End Function
107
[482]108 /*
109 @brief ファイルを作成する
110 @return ファイルストリーム
111 */
[466]112 Function Create() As FileStream
113 Return File.Create(FullPath)
114 End Function
115
[482]116 /*
117 @brief ファイルを作成し、そのストリームライターを取得する
118 @return ストリームライター
119 */
120 Function CreateText() As StreamWriter
121 Return New StreamWriter(Create())
122 End Function
[466]123
124/* Sub Decrypt()
125 End Sub*/
126
[482]127 /*
128 @brief ファイルを削除する
129 */
[466]130 Override Sub Delete()
131 File.Delete(FullPath)
132 End Sub
133
134/* Sub Encrypt()
135 End Sub*/
136
137/* Function GetAccessControl() As FileSecurity
138 End Function*/
139
140/* Function GetAccessControl(includeSections As AccessControlSections) As FileScurity
141 End Function*/
142
[482]143 /*
144 @brief ファイルを移動する
145 @param 移動先のファイルパス
146 */
[466]147 Sub MoveTo(destFileName As String)
148 File.Move(FullPath, destFileName)
149 End Sub
150
[482]151 /*
152 @brief ファイルストリームを作成する
153 @param ファイルモード
154 @return ファイルストリーム
155 */
[466]156 Function Open(mode As FileMode) As FileStream
157 Return New FileStream(FullPath, mode)
158 End Function
159
[482]160 /*
161 @brief ファイルストリームを作成する
162 @param ファイルモード
163 @param ファイルアクセス
164 @return ファイルストリーム
165 */
[466]166 Function Open(mode As FileMode, access As FileAccess) As FileStream
167 Return New FileStream(FullPath, mode, access)
168 End Function
169
[482]170 /*
171 @brief ファイルストリームを作成する
172 @param ファイルモード
173 @param ファイルアクセス
174 @param ファイル共有
175 @return ファイルストリーム
176 */
[466]177 Function Open(mode As FileMode, access As FileAccess, share As FileShare ) As FileStream
178 Return New FileStream(FullPath, mode, access, share)
179 End Function
180
[482]181 /*
182 @brief 読み取り専用のファイルストリームを作成する
183 @return ファイルストリーム
184 */
[466]185 Function OpenRead() As FileStream
186 Return Open(FileMode.Open, FileAccess.Read, FileShare.Read)
187 End Function
188
[482]189 /*
190 @brief 読み取り専用のストリームを作成する
191 @param ファイルパス
192 @return ストリームリーダー
193 */
[466]194 Function OpenText() As StreamReader
195 Return New StreamReader(FullPath)
196 End Function
197
[482]198 /*
199 @brief 書き込み専用のファイルストリームを作成する
200 @return ファイルストリーム
201 */
[466]202 Function OpenWrite() As FileStream
203 Return Open(FileMode.Open, FileAccess.Write)
204 End Function
205
[482]206 /*
207 @brief ファイルを置き換える
208 @param 置き換え先のファイルパス
209 @param 置き換えられるファイルのバックアップを作成するファイルパス
210 */
211 Function Replace(destinationFileName As String, destinationBackupFileName As String) As FileInfo
212 File.Replace(FullPath, destinationFileName, destinationBackupFileName)
213 End Function
[466]214
215/* Function Replace(destinationFileName As String, destinationBackupFileName As String, ignoreMetadataErrors As Boolean) As FileInfo
216 End Function*/
217
218/* Sub SetAccessControl(fileSecurity As FileSecurity)
219 End Sub*/
220
[482]221 /*
222 @brief インスタンスを文字列で表す
223 @return ファイルパス
224 */
[466]225 Override Function ToString() As String
226 Return FullPath
227 End Function
228
[60]229End Class
[271]230
231
232End Namespace
233End Namespace
Note: See TracBrowser for help on using the repository browser.