[83] | 1 | Class FileSystemInfo
|
---|
| 2 | Protected
|
---|
| 3 | FullPath As String
|
---|
| 4 | OriginalPath As String
|
---|
| 5 | Public
|
---|
| 6 | 'Public Properties
|
---|
| 7 | Function Attributes() As FileAttributes
|
---|
| 8 | Dim data As WIN32_FIND_DATA
|
---|
| 9 | If getFindFile(data) = False Then
|
---|
| 10 | 'Exception
|
---|
| 11 | Debug
|
---|
| 12 | Exit Function
|
---|
| 13 | End If
|
---|
| 14 | Select Case data.dwFileAttributes
|
---|
| 15 | Case FILE_ATTRIBUTE_ARCHIVE
|
---|
| 16 | Return Archive
|
---|
| 17 | Case FILE_ATTRIBUTE_COMPRESSED
|
---|
| 18 | Return Compressed
|
---|
| 19 | Case FILE_ATTRIBUTE_DIRECTORY
|
---|
| 20 | Return Directory
|
---|
| 21 | Case FILE_ATTRIBUTE_ENCRYPTED
|
---|
| 22 | Return Encrypted
|
---|
| 23 | Case FILE_ATTRIBUTE_HIDDEN
|
---|
| 24 | Return Hidden
|
---|
| 25 | Case FILE_ATTRIBUTE_NORMAL
|
---|
| 26 | Return Normal
|
---|
| 27 | Case FILE_ATTRIBUTE_OFFLINE
|
---|
| 28 | Return Offline
|
---|
| 29 | Case FILE_ATTRIBUTE_READONLY
|
---|
| 30 | Return ReadOnly
|
---|
| 31 | Case FILE_ATTRIBUTE_REPARSE_POINT
|
---|
| 32 | Return ReparsePoint
|
---|
| 33 | Case FILE_ATTRIBUTE_SPARSE_FILE
|
---|
| 34 | Return SparseFile
|
---|
| 35 | Case FILE_ATTRIBUTE_SYSTEM
|
---|
| 36 | Return System
|
---|
| 37 | Case FILE_ATTRIBUTE_TEMPORARY
|
---|
| 38 | Return Temporary
|
---|
| 39 | Case Else
|
---|
| 40 | 'Exception
|
---|
| 41 | Debug
|
---|
| 42 | Return 0
|
---|
| 43 | End Select
|
---|
| 44 | End Function
|
---|
| 45 |
|
---|
| 46 | Sub Attributes(ByRef value As FileAttributes)
|
---|
| 47 | Dim attributes As DWord
|
---|
| 48 | Select Case value
|
---|
| 49 | Case Archive
|
---|
| 50 | attributes = FILE_ATTRIBUTE_ARCHIVE
|
---|
| 51 | Case Compressed
|
---|
| 52 | attributes = FILE_ATTRIBUTE_COMPRESSED
|
---|
| 53 | Case Directory
|
---|
| 54 | attributes = FILE_ATTRIBUTE_DIRECTORY
|
---|
| 55 | Case Hidden
|
---|
| 56 | attributes = FILE_ATTRIBUTE_HIDDEN
|
---|
| 57 | Case Normal
|
---|
| 58 | attributes = FILE_ATTRIBUTE_NORMAL
|
---|
| 59 | Case Offline
|
---|
| 60 | attributes = FILE_ATTRIBUTE_OFFLINE
|
---|
| 61 | Case ReadOnly
|
---|
| 62 | attributes = FILE_ATTRIBUTE_READONLY
|
---|
| 63 | Case System
|
---|
| 64 | attributes = FILE_ATTRIBUTE_SYSTEM
|
---|
| 65 | Case Temporary
|
---|
| 66 | attributes = FILE_ATTRIBUTE_TEMPORARY
|
---|
| 67 | Case Else
|
---|
| 68 | 'Exception
|
---|
| 69 | Exit Sub
|
---|
| 70 | End Select
|
---|
| 71 |
|
---|
| 72 | If SetFileAttributes(FullPath, attributes) = FALSE Then
|
---|
| 73 | 'Exception
|
---|
| 74 | Debug
|
---|
| 75 | End If
|
---|
| 76 | End Sub
|
---|
| 77 |
|
---|
| 78 | Function CreationTime() As DateTime
|
---|
| 79 | Dim data As WIN32_FIND_DATA
|
---|
| 80 | If getFindFile(data) = False Then
|
---|
| 81 | 'Exception
|
---|
| 82 | Debug
|
---|
| 83 | End If
|
---|
| 84 | Return DateTime.FromFileTime(data.ftCreationTime)
|
---|
| 85 | End Function
|
---|
| 86 |
|
---|
| 87 | Sub CreationTime(ByRef value As DateTime)
|
---|
| 88 | If setFileTime(_CreationTime, value) = FALSE Then
|
---|
| 89 | 'Exception
|
---|
| 90 | debug
|
---|
| 91 | End If
|
---|
| 92 | End Sub
|
---|
| 93 |
|
---|
| 94 | Function CreationTimeUtc() As DateTime
|
---|
| 95 | Dim date = CreationTime As DateTime
|
---|
| 96 | Return date.ToUniversalTime()
|
---|
| 97 | End Function
|
---|
| 98 |
|
---|
| 99 | Sub CreationTimeUtc(ByRef value As DateTime)
|
---|
| 100 | CreationTime = value
|
---|
| 101 | End Sub
|
---|
| 102 |
|
---|
| 103 | Function LastAccessTime() As DateTime
|
---|
| 104 | Dim data As WIN32_FIND_DATA
|
---|
| 105 | If getFindFile(data) = False Then
|
---|
| 106 | 'Exception
|
---|
| 107 | Debug
|
---|
| 108 | End If
|
---|
| 109 | Return DateTime.FromFileTime(data.ftLastAccessTime)
|
---|
| 110 | End Function
|
---|
| 111 |
|
---|
| 112 | Sub LastAccessTime(ByRef value As DateTime)
|
---|
| 113 | If setFileTime(_LastAccessTime, value) = FALSE Then
|
---|
| 114 | 'Exception
|
---|
| 115 | debug
|
---|
| 116 | End If
|
---|
| 117 | End Sub
|
---|
| 118 |
|
---|
| 119 | Function LastAccessTimeUtc() As DateTime
|
---|
| 120 | Dim date = LastAccessTime As DateTime
|
---|
| 121 | Return date.ToUniversalTime()
|
---|
| 122 | End Function
|
---|
| 123 |
|
---|
| 124 | Sub LastAccessTimeUtc(ByRef value As DateTime)
|
---|
| 125 | LastAccessTime = value
|
---|
| 126 | End Sub
|
---|
| 127 |
|
---|
| 128 | Function LastWriteTime() As DateTime
|
---|
| 129 | Dim data As WIN32_FIND_DATA
|
---|
| 130 | If getFindFile(data) = False Then
|
---|
| 131 | 'Exception
|
---|
| 132 | Debug
|
---|
| 133 | End If
|
---|
| 134 | Return DateTime.FromFileTime(data.ftLastWriteTime)
|
---|
| 135 | End Function
|
---|
| 136 |
|
---|
| 137 | Sub LastWriteTime(ByRef value As DateTime)
|
---|
| 138 | If setFileTime(_LastWriteTime, value) = FALSE Then
|
---|
| 139 | 'Exception
|
---|
| 140 | debug
|
---|
| 141 | End If
|
---|
| 142 | End Sub
|
---|
| 143 |
|
---|
| 144 | Function LastWriteTimeUtc() As DateTime
|
---|
| 145 | Dim date = LastWriteTime As DateTime
|
---|
| 146 | Return date.ToUniversalTime()
|
---|
| 147 | End Function
|
---|
| 148 |
|
---|
| 149 | Sub LastWriteTimeUtc(ByRef value As DateTime)
|
---|
| 150 | LastWriteTime = value
|
---|
| 151 | End Sub
|
---|
| 152 |
|
---|
| 153 | Function Exists() As Boolean
|
---|
| 154 | Dim data As WIN32_FIND_DATA
|
---|
| 155 | Return getFindFile(data)
|
---|
| 156 | End Function
|
---|
| 157 |
|
---|
| 158 | Function Extension() As String
|
---|
| 159 | Return Path.GetExtension(FullPath)
|
---|
| 160 | End Function
|
---|
| 161 |
|
---|
| 162 | Function FullName() As String
|
---|
| 163 | Return FullPath
|
---|
| 164 | End Function
|
---|
| 165 |
|
---|
| 166 | Function Name() As String
|
---|
| 167 | Return Path.GetFileName(FullPath)
|
---|
| 168 | End Function
|
---|
| 169 |
|
---|
| 170 | 'Public Methods
|
---|
| 171 | Virtual Sub Delete()
|
---|
| 172 | If DeleteFile(FullPath) = FALSE Then
|
---|
| 173 | 'Exception
|
---|
| 174 | debug
|
---|
| 175 | End If
|
---|
| 176 | End Sub
|
---|
| 177 |
|
---|
| 178 | '未実装
|
---|
| 179 | Sub Refresh()
|
---|
| 180 | End Sub
|
---|
| 181 |
|
---|
| 182 | Private
|
---|
| 183 | Function getFindFile(ByRef data As WIN32_FIND_DATA) As Boolean
|
---|
| 184 | Dim hFind As HANDLE
|
---|
| 185 | hFind = FindFirstFile(FullPath, data)
|
---|
| 186 | If hFind = INVALID_HANDLE_VALUE Then
|
---|
| 187 | Return False
|
---|
| 188 | Else
|
---|
| 189 | CloseHandle(hFind)
|
---|
| 190 | Return True
|
---|
| 191 | End If
|
---|
| 192 | End Function
|
---|
| 193 |
|
---|
| 194 | '任意のファイル日時を変更する。flagsに、どの日時を変更するかを指定する。
|
---|
| 195 | Function setFileTime(flags As _FileTimeType, ByRef value As DateTime) As Boolean
|
---|
| 196 | Dim hFile As HANDLE
|
---|
| 197 | hFile = CreateFile(FullPath, GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0)
|
---|
| 198 | If hFile = INVALID_HANDLE_VALUE Then
|
---|
| 199 | setFileTime = FALSE
|
---|
| 200 | Exit Function
|
---|
| 201 | End If
|
---|
| 202 |
|
---|
| 203 | Dim fileTime As FILETIME
|
---|
| 204 | Dim results As Long
|
---|
| 205 | fileTime = value.ToFileTimeUtc()
|
---|
| 206 | Select Case flags
|
---|
| 207 | Case _CreationTime
|
---|
| 208 | results = SetFileTime(hFile, fileTime, ByVal 0, ByVal 0)
|
---|
| 209 | Case _LastAccessTime
|
---|
| 210 | results = SetFileTime(hFile, ByVal 0, fileTime, ByVal 0)
|
---|
| 211 | Case _LastWriteTime
|
---|
| 212 | results = SetFileTime(hFile, ByVal 0, ByVal 0, fileTime)
|
---|
| 213 | End Select
|
---|
| 214 | CloseHandle(hFile)
|
---|
| 215 |
|
---|
| 216 | If results Then
|
---|
| 217 | Return True
|
---|
| 218 | Else
|
---|
| 219 | Return False
|
---|
| 220 | End If
|
---|
| 221 | End Function
|
---|
| 222 | End Class
|
---|
| 223 |
|
---|
| 224 | Const Enum _FileTimeType
|
---|
| 225 | _CreationTime
|
---|
| 226 | _LastAccessTime
|
---|
| 227 | _LastWriteTime
|
---|
| 228 | End Enum
|
---|