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