source: trunk/Include/Classes/System/IO/FileSystemInfo.ab@ 346

Last change on this file since 346 was 346, checked in by OverTaker, 17 years ago

ミス修整

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