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 |
|
---|
15 | Override Function Equals( object As Object ) As Boolean
|
---|
16 | If This.ToString = object.ToString Then
|
---|
17 | Return True
|
---|
18 | Else
|
---|
19 | Return False
|
---|
20 | End If
|
---|
21 | End Function
|
---|
22 |
|
---|
23 | Override Function ToString() As String
|
---|
24 | Return FullPath
|
---|
25 | End Function
|
---|
26 |
|
---|
27 | 'Public Properties
|
---|
28 | Function Attributes() As DWord'FileAttributes
|
---|
29 | Return m_FileAttributes
|
---|
30 | End Function
|
---|
31 |
|
---|
32 | Sub Attributes(value As DWord)
|
---|
33 | If SetFileAttributes(FullPath, value) = FALSE Then
|
---|
34 | 'Exception
|
---|
35 | Debug
|
---|
36 | End If
|
---|
37 | End Sub
|
---|
38 |
|
---|
39 | Function CreationTime() As DateTime
|
---|
40 | Return DateTime.FromFileTime(m_CreationTime)
|
---|
41 | End Function
|
---|
42 |
|
---|
43 | Sub CreationTime(ByRef value As DateTime)
|
---|
44 | m_CreationTime = value.ToFileTimeUtc()
|
---|
45 | If setFileTime() = False Then
|
---|
46 | 'Exception
|
---|
47 | debug
|
---|
48 | End If
|
---|
49 | End Sub
|
---|
50 |
|
---|
51 | Function CreationTimeUtc() As DateTime
|
---|
52 | Dim date = CreationTime As DateTime
|
---|
53 | Return date.ToUniversalTime()
|
---|
54 | End Function
|
---|
55 |
|
---|
56 | Sub CreationTimeUtc(ByRef value As DateTime)
|
---|
57 | CreationTime = value
|
---|
58 | End Sub
|
---|
59 |
|
---|
60 | Function LastAccessTime() As DateTime
|
---|
61 | Return DateTime.FromFileTime(m_LastAccessTime)
|
---|
62 | End Function
|
---|
63 |
|
---|
64 | Sub LastAccessTime(ByRef value As DateTime)
|
---|
65 | m_LastAccessTime = value.ToFileTimeUtc()
|
---|
66 | If setFileTime() = False Then
|
---|
67 | 'Exception
|
---|
68 | debug
|
---|
69 | End If
|
---|
70 | End Sub
|
---|
71 |
|
---|
72 | Function LastAccessTimeUtc() As DateTime
|
---|
73 | Dim date = LastAccessTime As DateTime
|
---|
74 | Return date.ToUniversalTime()
|
---|
75 | End Function
|
---|
76 |
|
---|
77 | Sub LastAccessTimeUtc(ByRef value As DateTime)
|
---|
78 | LastAccessTime = value
|
---|
79 | End Sub
|
---|
80 |
|
---|
81 | Function LastWriteTime() As DateTime
|
---|
82 | Return DateTime.FromFileTime(m_LastWriteTime)
|
---|
83 | End Function
|
---|
84 |
|
---|
85 | Sub LastWriteTime(ByRef value As DateTime)
|
---|
86 | m_LastWriteTime = value.ToFileTimeUtc()
|
---|
87 | If setFileTime() = False Then
|
---|
88 | 'Exception
|
---|
89 | debug
|
---|
90 | End If
|
---|
91 | End Sub
|
---|
92 |
|
---|
93 | Function LastWriteTimeUtc() As DateTime
|
---|
94 | Dim date = LastWriteTime As DateTime
|
---|
95 | Return date.ToUniversalTime()
|
---|
96 | End Function
|
---|
97 |
|
---|
98 | Sub LastWriteTimeUtc(ByRef value As DateTime)
|
---|
99 | LastWriteTime = value
|
---|
100 | End Sub
|
---|
101 |
|
---|
102 | Function Exists() As Boolean
|
---|
103 | If m_FileAttributes = 0 Then
|
---|
104 | Return False
|
---|
105 | Else
|
---|
106 | Return True
|
---|
107 | End If
|
---|
108 | End Function
|
---|
109 |
|
---|
110 | Function Extension() As String
|
---|
111 | Return Path.GetExtension(FullPath)
|
---|
112 | End Function
|
---|
113 |
|
---|
114 | Function FullName() As String
|
---|
115 | Return FullPath
|
---|
116 | End Function
|
---|
117 |
|
---|
118 | Function Name() As String
|
---|
119 | Return Path.GetFileName(FullPath)
|
---|
120 | End Function
|
---|
121 |
|
---|
122 | 'Public Methods
|
---|
123 | Virtual Sub Delete()
|
---|
124 | If DeleteFile(FullPath) = FALSE Then
|
---|
125 | 'Exception
|
---|
126 | debug
|
---|
127 | End If
|
---|
128 | End Sub
|
---|
129 |
|
---|
130 | Virtual Sub Refresh()
|
---|
131 | Dim data As WIN32_FIND_DATA
|
---|
132 | Dim hFind = FindFirstFile(ToTCStr(FullPath), data)
|
---|
133 | FindClose(hFind)
|
---|
134 |
|
---|
135 | m_FileAttributes = data.dwFileAttributes
|
---|
136 | m_CreationTime = data.ftCreationTime
|
---|
137 | m_LastAccessTime = data.ftLastAccessTime
|
---|
138 | m_LastWriteTime = data.ftLastWriteTime
|
---|
139 | End Sub
|
---|
140 |
|
---|
141 | Private
|
---|
142 | Function setFileTime() As Boolean
|
---|
143 | Dim hFile = CreateFile(ToTCStr(FullPath), GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0)
|
---|
144 | If hFile = INVALID_HANDLE_VALUE Then
|
---|
145 | setFileTime = False
|
---|
146 | Exit Function
|
---|
147 | End If
|
---|
148 |
|
---|
149 | If SetFileTime(hFile, m_CreationTime, m_LastAccessTime, m_LastWriteTime) Then
|
---|
150 | setFileTime = True
|
---|
151 | Else
|
---|
152 | setFileTime = False
|
---|
153 | End If
|
---|
154 |
|
---|
155 | CloseHandle(hFile)
|
---|
156 | End Function
|
---|
157 | End Class
|
---|
158 |
|
---|
159 |
|
---|
160 | End Namespace
|
---|
161 | End Namespace
|
---|