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