Class FileSystemInfo Protected FullPath As String OriginalPath As String Public 'Public Properties Function Attributes() As FileAttributes Dim data As WIN32_FIND_DATA If getFindFile(data) = False Then 'Exception Debug Exit Function End If Select Case data.dwFileAttributes Case FILE_ATTRIBUTE_ARCHIVE Return Archive Case FILE_ATTRIBUTE_COMPRESSED Return Compressed Case FILE_ATTRIBUTE_DIRECTORY Return Directory Case FILE_ATTRIBUTE_ENCRYPTED Return Encrypted Case FILE_ATTRIBUTE_HIDDEN Return Hidden Case FILE_ATTRIBUTE_NORMAL Return Normal Case FILE_ATTRIBUTE_OFFLINE Return Offline Case FILE_ATTRIBUTE_READONLY Return ReadOnly Case FILE_ATTRIBUTE_REPARSE_POINT Return ReparsePoint Case FILE_ATTRIBUTE_SPARSE_FILE Return SparseFile Case FILE_ATTRIBUTE_SYSTEM Return System Case FILE_ATTRIBUTE_TEMPORARY Return Temporary Case Else 'Exception Debug Return 0 End Select End Function Sub Attributes(ByRef value As FileAttributes) Dim attributes As DWord Select Case value Case Archive attributes = FILE_ATTRIBUTE_ARCHIVE Case Compressed attributes = FILE_ATTRIBUTE_COMPRESSED Case Directory attributes = FILE_ATTRIBUTE_DIRECTORY Case Hidden attributes = FILE_ATTRIBUTE_HIDDEN Case Normal attributes = FILE_ATTRIBUTE_NORMAL Case Offline attributes = FILE_ATTRIBUTE_OFFLINE Case ReadOnly attributes = FILE_ATTRIBUTE_READONLY Case System attributes = FILE_ATTRIBUTE_SYSTEM Case Temporary attributes = FILE_ATTRIBUTE_TEMPORARY Case Else 'Exception Exit Sub End Select If SetFileAttributes(FullPath, attributes) = FALSE Then 'Exception Debug End If End Sub Function CreationTime() As DateTime Dim data As WIN32_FIND_DATA If getFindFile(data) = False Then 'Exception Debug End If Return DateTime.FromFileTime(data.ftCreationTime) End Function Sub CreationTime(ByRef value As DateTime) If setFileTime(_CreationTime, value) = FALSE Then 'Exception debug End If End Sub Function CreationTimeUtc() As DateTime Dim date = CreationTime As DateTime Return date.ToUniversalTime() End Function Sub CreationTimeUtc(ByRef value As DateTime) CreationTime = value End Sub Function LastAccessTime() As DateTime Dim data As WIN32_FIND_DATA If getFindFile(data) = False Then 'Exception Debug End If Return DateTime.FromFileTime(data.ftLastAccessTime) End Function Sub LastAccessTime(ByRef value As DateTime) If setFileTime(_LastAccessTime, value) = FALSE Then 'Exception debug End If End Sub Function LastAccessTimeUtc() As DateTime Dim date = LastAccessTime As DateTime Return date.ToUniversalTime() End Function Sub LastAccessTimeUtc(ByRef value As DateTime) LastAccessTime = value End Sub Function LastWriteTime() As DateTime Dim data As WIN32_FIND_DATA If getFindFile(data) = False Then 'Exception Debug End If Return DateTime.FromFileTime(data.ftLastWriteTime) End Function Sub LastWriteTime(ByRef value As DateTime) If setFileTime(_LastWriteTime, value) = FALSE Then 'Exception debug End If End Sub Function LastWriteTimeUtc() As DateTime Dim date = LastWriteTime As DateTime Return date.ToUniversalTime() End Function Sub LastWriteTimeUtc(ByRef value As DateTime) LastWriteTime = value End Sub Function Exists() As Boolean Dim data As WIN32_FIND_DATA Return getFindFile(data) End Function Function Extension() As String Return Path.GetExtension(FullPath) End Function Function FullName() As String Return FullPath End Function Function Name() As String Return Path.GetFileName(FullPath) End Function 'Public Methods Virtual Sub Delete() If DeleteFile(FullPath) = FALSE Then 'Exception debug End If End Sub '未実装 Sub Refresh() End Sub Private Function getFindFile(ByRef data As WIN32_FIND_DATA) As Boolean Dim hFind As HANDLE hFind = FindFirstFile(FullPath, data) If hFind = INVALID_HANDLE_VALUE Then Return False Else CloseHandle(hFind) Return True End If End Function '任意のファイル日時を変更する。flagsに、どの日時を変更するかを指定する。 Function setFileTime(flags As _FileTimeType, ByRef value As DateTime) As Boolean Dim hFile As HANDLE hFile = CreateFile(FullPath, GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0) If hFile = INVALID_HANDLE_VALUE Then setFileTime = FALSE Exit Function End If Dim fileTime As FILETIME Dim results As Long fileTime = value.ToFileTimeUtc() Select Case flags Case _CreationTime results = SetFileTime(hFile, fileTime, ByVal 0, ByVal 0) Case _LastAccessTime results = SetFileTime(hFile, ByVal 0, fileTime, ByVal 0) Case _LastWriteTime results = SetFileTime(hFile, ByVal 0, ByVal 0, fileTime) End Select CloseHandle(hFile) If results Then Return True Else Return False End If End Function End Class Const Enum _FileTimeType _CreationTime _LastAccessTime _LastWriteTime End Enum