Namespace System Namespace IO Enum FileAccess Read = GENERIC_READ ReadWrite = GENERIC_READ Or GENERIC_WRITE Write = GENERIC_WRITE End Enum Enum FileAttributes Archive = FILE_ATTRIBUTE_ARCHIVE Compressed = FILE_ATTRIBUTE_COMPRESSED Device = FILE_ATTRIBUTE_DEVICE Directory = FILE_ATTRIBUTE_DIRECTORY Encrypted = FILE_ATTRIBUTE_ENCRYPTED Hidden = FILE_ATTRIBUTE_HIDDEN Normal = FILE_ATTRIBUTE_NORMAL NotContentIndexed = FILE_ATTRIBUTE_NOT_CONTENT_INDEXED Offline = FILE_ATTRIBUTE_OFFLINE ReadOnly = FILE_ATTRIBUTE_READONLY ReparsePoint = FILE_ATTRIBUTE_REPARSE_POINT SparseFile = FILE_ATTRIBUTE_SPARSE_FILE System = FILE_ATTRIBUTE_SYSTEM Temporary = FILE_ATTRIBUTE_TEMPORARY End Enum Enum FileMode Append = OPEN_ALWAYS Create = CREATE_ALWAYS CreateNew = CREATE_NEW Open = OPEN_EXISTING OpenOrCreate = OPEN_ALWAYS Truncate = TRUNCATE_EXISTING End Enum Enum FileShare None = 0 Read = FILE_SHARE_READ Write = FILE_SHARE_WRITE ReadWrite = FILE_SHARE_READ Or FILE_SHARE_WRITE DeleteFile = FILE_SHARE_DELETE End Enum Class File Public '---------------------------------------------------------------- ' パブリック メソッド '---------------------------------------------------------------- /* Static Sub AppendAllText( path As String, contents As String ) ' TODO: 実装 End Sub*/ /* Static Sub AppendAllText( path As String, contents As String, encoding As Encoding ) ' TODO: 実装 End Sub */ /* Static Function AppendText( path As String ) As StreamWriter ' TODO: 実装 End Function*/ Static Sub Copy( sourceFileName As String, destFileName As String ) Copy(sourceFileName, destFileName, False) End Sub Static Sub Copy( sourceFileName As String, destFileName As String, overwrite As Boolean ) If Not CopyFile(Path.GetFullPath(sourceFileName), Path.GetFullPath(destFileName), overwrite) Then Throw New IOException( "FileInfo: Failed to CopyFile." ) End If End Sub Static Function Create( path As String ) As FileStream Return New FileStream(path, FileMode.CreateNew, FileAccess.ReadWrite) End Function /* Static Function Create( path As String, bufferSize As Long ) As FileStream ' TODO: 実装 End Function */ /* Static Function Create( path As String, bufferSize As Long, options As FileOptions ) As FileStream ' TODO: 実装 End Function */ /* Static Function Create( path As String, bufferSize As Long, options As FileOptions, fileSecurity As FileSecurity ) As FileStream ' TODO: 実装 End Function */ /* Static Function CreateText( path As String ) As StreamWriter ' TODO: 実装 End Function*/ /* Static Sub Decrypt( path As String ) ' TODO: 実装 End Sub*/ Static Sub Delete( path As String ) If Not DeleteFile(path) Then Throw New IOException("File.Delete: Failed to DeleteFile.") End If End Sub /* Static Sub Encrypt( path As String ) ' TODO: 実装 End Sub*/ Static Function Exists( path As String ) As Boolean Dim data As WIN32_FIND_DATA Dim hFind = FindFirstFile(ToTCStr(path), data) FindClose(hFind) If hFind <> INVALID_HANDLE_VALUE Then Return True Else Return False End If End Function /* Static Function GetAccessControl( path As String ) As FileSecurity ' TODO: 実装 End Function */ /* Static Function GetAccessControl( path As String, includeSections As AccessControlSections ) As FileSecurity ' TODO: 実装 End Function */ Static Function GetAttributes( path As String ) As FileAttributes Return New FileAttributes(getFileData(path).dwFileAttributes As Long, "FileAttributes") End Function Static Function GetCreationTime( path As String ) As DateTime Return System.DateTime.FromFileTime(getFileData(path).ftCreationTime) End Function Static Function GetCreationTimeUtc( path As String ) As DateTime Return System.DateTime.FromFileTimeUtc(getFileData(path).ftCreationTime) End Function Static Function GetLastAccessTime( path As String ) As DateTime Return System.DateTime.FromFileTime(getFileData(path).ftLastAccessTime) End Function Static Function GetLastAccessTimeUtc( path As String ) As DateTime Return System.DateTime.FromFileTimeUtc(getFileData(path).ftLastAccessTime) End Function Static Function GetLastWriteTime( path As String ) As DateTime Return System.DateTime.FromFileTime(getFileData(path).ftLastWriteTime) End Function Static Function GetLastWriteTimeUtc( path As String ) As DateTime Return System.DateTime.FromFileTimeUtc(getFileData(path).ftLastWriteTime) End Function Static Sub Move( sourceFileName As String, destFileName As String ) If Not MoveFile(Path.GetFullPath(sourceFileName), Path.GetFullPath(destFileName)) Then Throw New IOException("File.Move: Failed to MoveFile.") End If End Sub Static Function Open( path As String, mode As FileMode ) As FileStream Return New FileStream(path, mode) End Function Static Function Open( path As String, mode As FileMode, access As FileAccess ) As FileStream Return New FileStream(path, mode, access) End Function Static Function Open( path As String, mode As FileMode, access As FileAccess, share As FileShare ) As FileStream Return New FileStream(path, mode, access, share) End Function Static Function OpenRead( path As String ) As FileStream Return Open(path, FileMode.Open, FileAccess.Read, FileShare.Read) End Function Static Function OpenText( path As String ) As StreamReader Return New StreamReader(path) End Function Static Function OpenWrite( path As String ) As FileStream Return Open(path, FileMode.Open, FileAccess.Write) End Function /* Static Function ReadAllBytes( path As String ) As *Byte ' TODO: 実装 End Function*/ /* Static Function ReadAllLines( path As String ) As Strings ' TODO: 実装 End Function */ /* Static Function ReadAllLines( path As String, encoding As Encoding ) As Strings ' TODO: 実装 End Function */ /* Static Function ReadAllText( path As String ) As String ' TODO: 実装 End Function*/ /* Static Function ReadAllText( path As String, encoding As Encoding ) As String ' TODO: 実装 End Function */ /* Static Sub Replace( sourceFileName As String, destinationFileName As String, destinationBackupFileName As String ) ' TODO: 実装 End Sub*/ /* Static Sub Replace( sourceFileName As String, destinationFileName As String, destinationBackupFileName As String, ignoreMetadataErrors As Boolean ) ' TODO: 実装 End Sub*/ /* Static Sub SetAccessControl( path As String, fileSecurity As FileSecurity ) ' TODO: 実装 End Sub */ Static Sub SetAttributes( path As String, fileAttributes As FileAttributes ) If Not SetFileAttributes(ToTCStr(path), fileAttributes) Then Throw New IOException("File.SetAttributes: Failed to SetFileAttributes.") End If End Sub Static Sub SetCreationTime( path As String, creationTime As DateTime ) SetCreationTimeUtc(path, creationTime) End Sub Static Sub SetCreationTimeUtc( path As String, creationTimeUtc As DateTime ) Dim hFile = createFileToSetTime(path) As HANDLE SetFileTime(hFile, creationTimeUtc.ToFileTimeUtc(), ByVal 0, ByVal 0) CloseHandle(hFile) End Sub Static Sub SetLastAccessTime( path As String, lastAccessTime As DateTime ) SetLastAccessTimeUtc(path, lastAccessTime) End Sub Static Sub SetLastAccessTimeUtc( path As String, lastAccessTimeUtc As DateTime ) Dim hFile = createFileToSetTime(path) As HANDLE SetFileTime(hFile, ByVal 0, lastAccessTimeUtc.ToFileTimeUtc(), ByVal 0) CloseHandle(hFile) End Sub Static Sub SetLastWriteTime( path As String, lastWriteTime As DateTime ) SetLastWriteTimeUtc(path, lastWriteTime) End Sub Static Sub SetLastWriteTimeUtc( path As String, lastWriteTimeUtc As DateTime ) Dim hFile = createFileToSetTime(path) As HANDLE SetFileTime(hFile, ByVal 0, ByVal 0, lastWriteTimeUtc.ToFileTimeUtc()) CloseHandle(hFile) End Sub /* Static Sub WriteAllBytes( path As String, bytes As *Byte ) ' TODO: 実装 End Sub*/ /* Static Sub WriteAllLines( path As String, contents As Strings ) ' TODO: 実装 End Sub */ /* Static Sub WriteAllLines( path As String, contents As Strings, encoding As Enconding ) ' TODO: 実装 End Sub */ /* Static Sub WriteAllText( path As String, contents As String ) ' TODO: 実装 End Sub*/ /* Static Sub WriteAllText( path As String, contents As String, encoding As Enconding ) ' TODO: 実装 End Sub */ Private Static Function getFileData(path As String) As WIN32_FIND_DATA Dim data As WIN32_FIND_DATA Dim hFind = FindFirstFile(ToTCStr(Path.GetFullPath(path)), data) FindClose(hFind) If hFind <> INVALID_HANDLE_VALUE Then Return data Else Throw New IOException("File.getFileData: Failed to FindFirstFile.") End If End Function Static Function createFileToSetTime(path As String) As HANDLE Dim hFile As HANDLE hFile = CreateFile(ToTCStr(path), GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0) If hFile = INVALID_HANDLE_VALUE Then CloseHandle(hFile) Throw New IOException("File.setFileTime: Failed to CreateFile.") Exit Function End If Return hFile End Function End Class End Namespace End Namespace