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