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

Last change on this file since 87 was 84, checked in by OverTaker, 18 years ago

実装内容を変更。

File size: 4.5 KB
Line 
1Class FileSystemInfo
2 m_CreationTime As FILETIME
3 m_LastAccessTime As FILETIME
4 m_LastWriteTime As FILETIME
5 m_FileAttributes As DWord
6Protected
7 FullPath As String
8 OriginalPath As String
9Public
10 'Public Properties
11 Function Attributes() As FileAttributes
12 Select Case m_FileAttributes
13 Case FILE_ATTRIBUTE_ARCHIVE
14 Return Archive
15 Case FILE_ATTRIBUTE_COMPRESSED
16 Return Compressed
17 Case FILE_ATTRIBUTE_DIRECTORY
18 Return Directory
19 Case FILE_ATTRIBUTE_ENCRYPTED
20 Return Encrypted
21 Case FILE_ATTRIBUTE_HIDDEN
22 Return Hidden
23 Case FILE_ATTRIBUTE_NORMAL
24 Return Normal
25 Case FILE_ATTRIBUTE_OFFLINE
26 Return Offline
27 Case FILE_ATTRIBUTE_READONLY
28 Return ReadOnly
29 Case FILE_ATTRIBUTE_REPARSE_POINT
30 Return ReparsePoint
31 Case FILE_ATTRIBUTE_SPARSE_FILE
32 Return SparseFile
33 Case FILE_ATTRIBUTE_SYSTEM
34 Return System
35 Case FILE_ATTRIBUTE_TEMPORARY
36 Return 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 Archive
48 attributes = FILE_ATTRIBUTE_ARCHIVE
49 Case Compressed
50 attributes = FILE_ATTRIBUTE_COMPRESSED
51 Case Directory
52 attributes = FILE_ATTRIBUTE_DIRECTORY
53 Case Hidden
54 attributes = FILE_ATTRIBUTE_HIDDEN
55 Case Normal
56 attributes = FILE_ATTRIBUTE_NORMAL
57 Case Offline
58 attributes = FILE_ATTRIBUTE_OFFLINE
59 Case ReadOnly
60 attributes = FILE_ATTRIBUTE_READONLY
61 Case System
62 attributes = FILE_ATTRIBUTE_SYSTEM
63 Case 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 Sub Refresh()
168 Dim data As WIN32_FIND_DATA
169 Dim hFind As HANDLE
170 hFind = FindFirstFile(FullPath, data)
171 CloseHandle(hFind)
172
173 m_FileAttributes = data.dwFileAttributes
174 m_CreationTime = data.ftCreationTime
175 m_LastAccessTime = data.ftLastAccessTime
176 m_LastWriteTime = data.ftLastWriteTime
177 End Sub
178
179Private
180 Function setFileTime() As Boolean
181 Dim hFile As HANDLE
182 hFile = CreateFile(FullPath, GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0)
183 If hFile = INVALID_HANDLE_VALUE Then
184 setFileTime = False
185 Exit Function
186 End If
187
188 If SetFileTime(hFile, m_CreationTime, m_LastAccessTime, m_LastWriteTime) Then
189 setFileTime = True
190 Else
191 setFileTime = False
192 End If
193
194 CloseHandle(hFile)
195 End Function
196End Class
Note: See TracBrowser for help on using the repository browser.