source: Include/Classes/System/IO/FileSystemInfo.ab@ 271

Last change on this file since 271 was 271, checked in by dai, 17 years ago

SHFILEOPSTRUCT.hWnd → SHFILEOPSTRUCT.hwnd
System.IOに属するクラスに名前空間を適用した。

File size: 4.9 KB
Line 
1Namespace System
2Namespace IO
3
4
5Class FileSystemInfo
6 m_CreationTime As FILETIME
7 m_LastAccessTime As FILETIME
8 m_LastWriteTime As FILETIME
9 m_FileAttributes As DWord
10Protected
11 FullPath As String
12 OriginalPath As String
13Public
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 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
51 Case FileAttributes.Archive
52 attributes = FILE_ATTRIBUTE_ARCHIVE
53 Case FileAttributes.Compressed
54 attributes = FILE_ATTRIBUTE_COMPRESSED
55 Case FileAttributes.Directory
56 attributes = FILE_ATTRIBUTE_DIRECTORY
57 Case FileAttributes.Hidden
58 attributes = FILE_ATTRIBUTE_HIDDEN
59 Case FileAttributes.Normal
60 attributes = FILE_ATTRIBUTE_NORMAL
61 Case FileAttributes.Offline
62 attributes = FILE_ATTRIBUTE_OFFLINE
63 Case FileAttributes.ReadOnly
64 attributes = FILE_ATTRIBUTE_READONLY
65 Case FileAttributes.System
66 attributes = FILE_ATTRIBUTE_SYSTEM
67 Case FileAttributes.Temporary
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
81 Return DateTime.FromFileTime(m_CreationTime)
82 End Function
83
84 Sub CreationTime(ByRef value As DateTime)
85 m_CreationTime = value.ToFileTimeUtc()
86 If setFileTime() = False Then
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
102 Return DateTime.FromFileTime(m_LastAccessTime)
103 End Function
104
105 Sub LastAccessTime(ByRef value As DateTime)
106 m_LastAccessTime = value.ToFileTimeUtc()
107 If setFileTime() = False Then
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
123 Return DateTime.FromFileTime(m_LastWriteTime)
124 End Function
125
126 Sub LastWriteTime(ByRef value As DateTime)
127 m_LastWriteTime = value.ToFileTimeUtc()
128 If setFileTime() = False Then
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
144 If m_FileAttributes = 0 Then
145 Return False
146 Else
147 Return True
148 End If
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
171 Virtual Sub Refresh()
172 Dim data As WIN32_FIND_DATA
173 Dim hFind = FindFirstFile(ToTCStr(FullPath), data)
174 FindClose(hFind)
175
176 m_FileAttributes = data.dwFileAttributes
177 m_CreationTime = data.ftCreationTime
178 m_LastAccessTime = data.ftLastAccessTime
179 m_LastWriteTime = data.ftLastWriteTime
180 End Sub
181
182Private
183 Function setFileTime() As Boolean
184 Dim hFile = CreateFile(ToTCStr(FullPath), GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0)
185 If hFile = INVALID_HANDLE_VALUE Then
186 setFileTime = False
187 Exit Function
188 End If
189
190 If SetFileTime(hFile, m_CreationTime, m_LastAccessTime, m_LastWriteTime) Then
191 setFileTime = True
192 Else
193 setFileTime = False
194 End If
195
196 CloseHandle(hFile)
197 End Function
198End Class
199
200
201End Namespace
202End Namespace
Note: See TracBrowser for help on using the repository browser.