[271] | 1 | Namespace System
|
---|
| 2 | Namespace IO
|
---|
[59] | 3 |
|
---|
[271] | 4 |
|
---|
[60] | 5 | Enum FileAccess
|
---|
[466] | 6 | Read = GENERIC_READ
|
---|
| 7 | ReadWrite = GENERIC_READ Or GENERIC_WRITE
|
---|
| 8 | Write = GENERIC_WRITE
|
---|
[60] | 9 | End Enum
|
---|
| 10 |
|
---|
[59] | 11 | Enum FileAttributes
|
---|
[466] | 12 | Archive = FILE_ATTRIBUTE_ARCHIVE
|
---|
| 13 | Compressed = FILE_ATTRIBUTE_COMPRESSED
|
---|
| 14 | Device = FILE_ATTRIBUTE_DEVICE
|
---|
| 15 | Directory = FILE_ATTRIBUTE_DIRECTORY
|
---|
| 16 | Encrypted = FILE_ATTRIBUTE_ENCRYPTED
|
---|
| 17 | Hidden = FILE_ATTRIBUTE_HIDDEN
|
---|
| 18 | Normal = FILE_ATTRIBUTE_NORMAL
|
---|
| 19 | NotContentIndexed = FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
|
---|
| 20 | Offline = FILE_ATTRIBUTE_OFFLINE
|
---|
| 21 | ReadOnly = FILE_ATTRIBUTE_READONLY
|
---|
| 22 | ReparsePoint = FILE_ATTRIBUTE_REPARSE_POINT
|
---|
| 23 | SparseFile = FILE_ATTRIBUTE_SPARSE_FILE
|
---|
| 24 | System = FILE_ATTRIBUTE_SYSTEM
|
---|
| 25 | Temporary = FILE_ATTRIBUTE_TEMPORARY
|
---|
[59] | 26 | End Enum
|
---|
| 27 |
|
---|
[60] | 28 | Enum FileMode
|
---|
[466] | 29 | Append = OPEN_ALWAYS
|
---|
| 30 | Create = CREATE_ALWAYS
|
---|
| 31 | CreateNew = CREATE_NEW
|
---|
| 32 | Open = OPEN_EXISTING
|
---|
| 33 | OpenOrCreate = OPEN_ALWAYS
|
---|
| 34 | Truncate = TRUNCATE_EXISTING
|
---|
[60] | 35 | End Enum
|
---|
| 36 |
|
---|
| 37 | Enum FileShare
|
---|
[466] | 38 | None = 0
|
---|
| 39 | Read = FILE_SHARE_READ
|
---|
| 40 | Write = FILE_SHARE_WRITE
|
---|
| 41 | ReadWrite = FILE_SHARE_READ Or FILE_SHARE_WRITE
|
---|
[432] | 42 | DeleteFile = FILE_SHARE_DELETE
|
---|
[101] | 43 | End Enum
|
---|
| 44 |
|
---|
[59] | 45 | Class File
|
---|
| 46 | Public
|
---|
| 47 |
|
---|
[466] | 48 | '----------------------------------------------------------------
|
---|
| 49 | ' パブリック メソッド
|
---|
| 50 | '----------------------------------------------------------------
|
---|
| 51 |
|
---|
| 52 | /* Static Sub AppendAllText( path As String, contents As String )
|
---|
[59] | 53 | ' TODO: 実装
|
---|
[466] | 54 | End Sub*/
|
---|
[59] | 55 |
|
---|
| 56 | /* Static Sub AppendAllText( path As String, contents As String, encoding As Encoding )
|
---|
| 57 | ' TODO: 実装
|
---|
| 58 | End Sub */
|
---|
| 59 |
|
---|
[466] | 60 | /* Static Function AppendText( path As String ) As StreamWriter
|
---|
[59] | 61 | ' TODO: 実装
|
---|
[466] | 62 | End Function*/
|
---|
[59] | 63 |
|
---|
| 64 | Static Sub Copy( sourceFileName As String, destFileName As String )
|
---|
[466] | 65 | Copy(sourceFileName, destFileName, False)
|
---|
[59] | 66 | End Sub
|
---|
| 67 |
|
---|
| 68 | Static Sub Copy( sourceFileName As String, destFileName As String, overwrite As Boolean )
|
---|
[466] | 69 | If Not CopyFile(Path.GetFullPath(sourceFileName), Path.GetFullPath(destFileName), overwrite) Then
|
---|
| 70 | Throw New IOException( "FileInfo: Failed to CopyFile." )
|
---|
| 71 | End If
|
---|
[59] | 72 | End Sub
|
---|
| 73 |
|
---|
| 74 | Static Function Create( path As String ) As FileStream
|
---|
[466] | 75 | Return New FileStream(path, FileMode.CreateNew, FileAccess.ReadWrite)
|
---|
[59] | 76 | End Function
|
---|
| 77 |
|
---|
[466] | 78 | /* Static Function Create( path As String, bufferSize As Long ) As FileStream
|
---|
[59] | 79 | ' TODO: 実装
|
---|
[466] | 80 | End Function */
|
---|
[59] | 81 |
|
---|
| 82 | /* Static Function Create( path As String, bufferSize As Long, options As FileOptions ) As FileStream
|
---|
| 83 | ' TODO: 実装
|
---|
| 84 | End Function */
|
---|
| 85 |
|
---|
| 86 | /* Static Function Create( path As String, bufferSize As Long, options As FileOptions, fileSecurity As FileSecurity ) As FileStream
|
---|
| 87 | ' TODO: 実装
|
---|
| 88 | End Function */
|
---|
| 89 |
|
---|
[466] | 90 | /* Static Function CreateText( path As String ) As StreamWriter
|
---|
[59] | 91 | ' TODO: 実装
|
---|
[466] | 92 | End Function*/
|
---|
[59] | 93 |
|
---|
[466] | 94 | /* Static Sub Decrypt( path As String )
|
---|
[59] | 95 | ' TODO: 実装
|
---|
[466] | 96 | End Sub*/
|
---|
[59] | 97 |
|
---|
[466] | 98 | Static Sub Delete( path As String )
|
---|
| 99 | If Not DeleteFile(path) Then
|
---|
| 100 | Throw New IOException("File.Delete: Failed to DeleteFile.")
|
---|
| 101 | End If
|
---|
[59] | 102 | End Sub
|
---|
| 103 |
|
---|
[466] | 104 | /* Static Sub Encrypt( path As String )
|
---|
[59] | 105 | ' TODO: 実装
|
---|
[466] | 106 | End Sub*/
|
---|
[59] | 107 |
|
---|
| 108 | Static Function Exists( path As String ) As Boolean
|
---|
[466] | 109 | Dim data As WIN32_FIND_DATA
|
---|
| 110 | Dim hFind = FindFirstFile(ToTCStr(path), data)
|
---|
| 111 | FindClose(hFind)
|
---|
| 112 |
|
---|
| 113 | If hFind <> INVALID_HANDLE_VALUE Then
|
---|
| 114 | Return True
|
---|
| 115 | Else
|
---|
| 116 | Return False
|
---|
| 117 | End If
|
---|
[59] | 118 | End Function
|
---|
| 119 |
|
---|
| 120 | /* Static Function GetAccessControl( path As String ) As FileSecurity
|
---|
| 121 | ' TODO: 実装
|
---|
| 122 | End Function */
|
---|
| 123 |
|
---|
| 124 | /* Static Function GetAccessControl( path As String, includeSections As AccessControlSections ) As FileSecurity
|
---|
| 125 | ' TODO: 実装
|
---|
| 126 | End Function */
|
---|
| 127 |
|
---|
| 128 | Static Function GetAttributes( path As String ) As FileAttributes
|
---|
[466] | 129 | Return New FileAttributes(getFileData(path).dwFileAttributes As Long, "FileAttributes")
|
---|
[59] | 130 | End Function
|
---|
| 131 |
|
---|
| 132 | Static Function GetCreationTime( path As String ) As DateTime
|
---|
[466] | 133 | Return System.DateTime.FromFileTime(getFileData(path).ftCreationTime)
|
---|
[59] | 134 | End Function
|
---|
| 135 |
|
---|
| 136 | Static Function GetCreationTimeUtc( path As String ) As DateTime
|
---|
[466] | 137 | Return System.DateTime.FromFileTimeUtc(getFileData(path).ftCreationTime)
|
---|
[59] | 138 | End Function
|
---|
| 139 |
|
---|
| 140 | Static Function GetLastAccessTime( path As String ) As DateTime
|
---|
[466] | 141 | Return System.DateTime.FromFileTime(getFileData(path).ftLastAccessTime)
|
---|
[59] | 142 | End Function
|
---|
| 143 |
|
---|
| 144 | Static Function GetLastAccessTimeUtc( path As String ) As DateTime
|
---|
[466] | 145 | Return System.DateTime.FromFileTimeUtc(getFileData(path).ftLastAccessTime)
|
---|
[59] | 146 | End Function
|
---|
| 147 |
|
---|
| 148 | Static Function GetLastWriteTime( path As String ) As DateTime
|
---|
[466] | 149 | Return System.DateTime.FromFileTime(getFileData(path).ftLastWriteTime)
|
---|
[59] | 150 | End Function
|
---|
| 151 |
|
---|
| 152 | Static Function GetLastWriteTimeUtc( path As String ) As DateTime
|
---|
[466] | 153 | Return System.DateTime.FromFileTimeUtc(getFileData(path).ftLastWriteTime)
|
---|
[59] | 154 | End Function
|
---|
| 155 |
|
---|
| 156 | Static Sub Move( sourceFileName As String, destFileName As String )
|
---|
[466] | 157 | If Not MoveFile(Path.GetFullPath(sourceFileName), Path.GetFullPath(destFileName)) Then
|
---|
| 158 | Throw New IOException("File.Move: Failed to MoveFile.")
|
---|
| 159 | End If
|
---|
[59] | 160 | End Sub
|
---|
[60] | 161 |
|
---|
| 162 | Static Function Open( path As String, mode As FileMode ) As FileStream
|
---|
[466] | 163 | Return New FileStream(path, mode)
|
---|
[60] | 164 | End Function
|
---|
| 165 |
|
---|
| 166 | Static Function Open( path As String, mode As FileMode, access As FileAccess ) As FileStream
|
---|
[466] | 167 | Return New FileStream(path, mode, access)
|
---|
[60] | 168 | End Function
|
---|
| 169 |
|
---|
| 170 | Static Function Open( path As String, mode As FileMode, access As FileAccess, share As FileShare ) As FileStream
|
---|
[466] | 171 | Return New FileStream(path, mode, access, share)
|
---|
[60] | 172 | End Function
|
---|
| 173 |
|
---|
| 174 | Static Function OpenRead( path As String ) As FileStream
|
---|
[466] | 175 | Return Open(path, FileMode.Open, FileAccess.Read, FileShare.Read)
|
---|
[60] | 176 | End Function
|
---|
| 177 |
|
---|
[466] | 178 | Static Function OpenText( path As String ) As StreamReader
|
---|
| 179 | Return New StreamReader(path)
|
---|
| 180 | End Function
|
---|
[60] | 181 |
|
---|
| 182 | Static Function OpenWrite( path As String ) As FileStream
|
---|
[466] | 183 | Return Open(path, FileMode.Open, FileAccess.Write)
|
---|
[60] | 184 | End Function
|
---|
| 185 |
|
---|
[466] | 186 | /* Static Function ReadAllBytes( path As String ) As *Byte
|
---|
[60] | 187 | ' TODO: 実装
|
---|
[466] | 188 | End Function*/
|
---|
[60] | 189 |
|
---|
| 190 | /* Static Function ReadAllLines( path As String ) As Strings
|
---|
| 191 | ' TODO: 実装
|
---|
| 192 | End Function */
|
---|
| 193 |
|
---|
| 194 | /* Static Function ReadAllLines( path As String, encoding As Encoding ) As Strings
|
---|
| 195 | ' TODO: 実装
|
---|
| 196 | End Function */
|
---|
| 197 |
|
---|
[466] | 198 | /* Static Function ReadAllText( path As String ) As String
|
---|
[60] | 199 | ' TODO: 実装
|
---|
[466] | 200 | End Function*/
|
---|
[60] | 201 |
|
---|
[105] | 202 | /* Static Function ReadAllText( path As String, encoding As Encoding ) As String
|
---|
[60] | 203 | ' TODO: 実装
|
---|
[105] | 204 | End Function */
|
---|
[60] | 205 |
|
---|
[466] | 206 | /* Static Sub Replace( sourceFileName As String, destinationFileName As String, destinationBackupFileName As String )
|
---|
[60] | 207 | ' TODO: 実装
|
---|
[466] | 208 | End Sub*/
|
---|
[60] | 209 |
|
---|
[466] | 210 | /* Static Sub Replace( sourceFileName As String, destinationFileName As String, destinationBackupFileName As String, ignoreMetadataErrors As Boolean )
|
---|
[60] | 211 | ' TODO: 実装
|
---|
[466] | 212 | End Sub*/
|
---|
[60] | 213 |
|
---|
[105] | 214 | /* Static Sub SetAccessControl( path As String, fileSecurity As FileSecurity )
|
---|
[60] | 215 | ' TODO: 実装
|
---|
[105] | 216 | End Sub */
|
---|
[60] | 217 |
|
---|
| 218 | Static Sub SetAttributes( path As String, fileAttributes As FileAttributes )
|
---|
[466] | 219 | If Not SetFileAttributes(ToTCStr(path), fileAttributes) Then
|
---|
| 220 | Throw New IOException("File.SetAttributes: Failed to SetFileAttributes.")
|
---|
| 221 | End If
|
---|
[60] | 222 | End Sub
|
---|
| 223 |
|
---|
| 224 | Static Sub SetCreationTime( path As String, creationTime As DateTime )
|
---|
[466] | 225 | SetCreationTimeUtc(path, creationTime)
|
---|
[60] | 226 | End Sub
|
---|
| 227 |
|
---|
[466] | 228 | Static Sub SetCreationTimeUtc( path As String, creationTimeUtc As DateTime )
|
---|
| 229 | Dim hFile = createFileToSetTime(path) As HANDLE
|
---|
| 230 | SetFileTime(hFile, creationTimeUtc.ToFileTimeUtc(), ByVal 0, ByVal 0)
|
---|
| 231 | CloseHandle(hFile)
|
---|
[60] | 232 | End Sub
|
---|
| 233 |
|
---|
| 234 | Static Sub SetLastAccessTime( path As String, lastAccessTime As DateTime )
|
---|
[466] | 235 | SetLastAccessTimeUtc(path, lastAccessTime)
|
---|
[60] | 236 | End Sub
|
---|
| 237 |
|
---|
| 238 | Static Sub SetLastAccessTimeUtc( path As String, lastAccessTimeUtc As DateTime )
|
---|
[466] | 239 | Dim hFile = createFileToSetTime(path) As HANDLE
|
---|
| 240 | SetFileTime(hFile, ByVal 0, lastAccessTimeUtc.ToFileTimeUtc(), ByVal 0)
|
---|
| 241 | CloseHandle(hFile)
|
---|
[60] | 242 | End Sub
|
---|
| 243 |
|
---|
| 244 | Static Sub SetLastWriteTime( path As String, lastWriteTime As DateTime )
|
---|
[466] | 245 | SetLastWriteTimeUtc(path, lastWriteTime)
|
---|
[60] | 246 | End Sub
|
---|
| 247 |
|
---|
| 248 | Static Sub SetLastWriteTimeUtc( path As String, lastWriteTimeUtc As DateTime )
|
---|
[466] | 249 | Dim hFile = createFileToSetTime(path) As HANDLE
|
---|
| 250 | SetFileTime(hFile, ByVal 0, ByVal 0, lastWriteTimeUtc.ToFileTimeUtc())
|
---|
| 251 | CloseHandle(hFile)
|
---|
[60] | 252 | End Sub
|
---|
| 253 |
|
---|
[466] | 254 | /* Static Sub WriteAllBytes( path As String, bytes As *Byte )
|
---|
[60] | 255 | ' TODO: 実装
|
---|
[466] | 256 | End Sub*/
|
---|
[60] | 257 |
|
---|
| 258 | /* Static Sub WriteAllLines( path As String, contents As Strings )
|
---|
| 259 | ' TODO: 実装
|
---|
| 260 | End Sub */
|
---|
| 261 |
|
---|
| 262 | /* Static Sub WriteAllLines( path As String, contents As Strings, encoding As Enconding )
|
---|
| 263 | ' TODO: 実装
|
---|
| 264 | End Sub */
|
---|
| 265 |
|
---|
[466] | 266 | /* Static Sub WriteAllText( path As String, contents As String )
|
---|
[60] | 267 | ' TODO: 実装
|
---|
[466] | 268 | End Sub*/
|
---|
[60] | 269 |
|
---|
[105] | 270 | /* Static Sub WriteAllText( path As String, contents As String, encoding As Enconding )
|
---|
[60] | 271 | ' TODO: 実装
|
---|
[105] | 272 | End Sub */
|
---|
[60] | 273 |
|
---|
[466] | 274 | Private
|
---|
| 275 |
|
---|
| 276 | Static Function getFileData(path As String) As WIN32_FIND_DATA
|
---|
| 277 | Dim data As WIN32_FIND_DATA
|
---|
| 278 | Dim hFind = FindFirstFile(ToTCStr(Path.GetFullPath(path)), data)
|
---|
| 279 | FindClose(hFind)
|
---|
| 280 |
|
---|
| 281 | If hFind <> INVALID_HANDLE_VALUE Then
|
---|
| 282 | Return data
|
---|
| 283 | Else
|
---|
| 284 | Throw New IOException("File.getFileData: Failed to FindFirstFile.")
|
---|
| 285 | End If
|
---|
| 286 | End Function
|
---|
| 287 |
|
---|
| 288 | Static Function createFileToSetTime(path As String) As HANDLE
|
---|
| 289 | Dim hFile As HANDLE
|
---|
| 290 | hFile = CreateFile(ToTCStr(path), GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0)
|
---|
| 291 | If hFile = INVALID_HANDLE_VALUE Then
|
---|
| 292 | CloseHandle(hFile)
|
---|
| 293 | Throw New IOException("File.setFileTime: Failed to CreateFile.")
|
---|
| 294 | Exit Function
|
---|
| 295 | End If
|
---|
| 296 | Return hFile
|
---|
| 297 | End Function
|
---|
[59] | 298 | End Class
|
---|
[271] | 299 |
|
---|
| 300 |
|
---|
| 301 | End Namespace
|
---|
| 302 | End Namespace
|
---|