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

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

DirectoryInfo.GetDirectoriesのバグ修整。

File size: 3.2 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
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 setFileTime()
46 End Sub
47
48 Function CreationTimeUtc() As DateTime
49 Return CreationTime.ToUniversalTime()
50 End Function
51
52 Sub CreationTimeUtc(ByRef value As DateTime)
53 CreationTime = value
54 End Sub
55
56 Function LastAccessTime() As DateTime
57 Return DateTime.FromFileTime(m_LastAccessTime)
58 End Function
59
60 Sub LastAccessTime(ByRef value As DateTime)
61 m_LastAccessTime = value.ToFileTimeUtc()
62 setFileTime()
63 End Sub
64
65 Function LastAccessTimeUtc() As DateTime
66 Return LastAccessTime.ToUniversalTime()
67 End Function
68
69 Sub LastAccessTimeUtc(ByRef value As DateTime)
70 LastAccessTime = value
71 End Sub
72
73 Function LastWriteTime() As DateTime
74 Return DateTime.FromFileTime(m_LastWriteTime)
75 End Function
76
77 Sub LastWriteTime(ByRef value As DateTime)
78 m_LastWriteTime = value.ToFileTimeUtc()
79 setFileTime()
80 End Sub
81
82 Function LastWriteTimeUtc() As DateTime
83 Return LastWriteTime.ToUniversalTime()
84 End Function
85
86 Sub LastWriteTimeUtc(ByRef value As DateTime)
87 LastWriteTime = value
88 End Sub
89
90 Function Exists() As Boolean
91 If m_FileAttributes = 0 Then
92 Return False
93 Else
94 Return True
95 End If
96 End Function
97
98 Function Extension() As String
99 Return Path.GetExtension(FullPath)
100 End Function
101
102 Function FullName() As String
103 Return FullPath
104 End Function
105
106 Function Name() As String
107 Return Path.GetFileName(FullPath)
108 End Function
109
110 'Public Methods
111 Virtual Sub Delete()
112 If DeleteFile(FullPath) = FALSE Then
113 'Exception
114 debug
115 End If
116 End Sub
117
118 Virtual Sub Refresh()
119 Dim data As WIN32_FIND_DATA
120 Dim hFind = FindFirstFile(ToTCStr(FullPath), data)
121 FindClose(hFind)
122
123 m_FileAttributes = data.dwFileAttributes
124 m_CreationTime = data.ftCreationTime
125 m_LastAccessTime = data.ftLastAccessTime
126 m_LastWriteTime = data.ftLastWriteTime
127 End Sub
128Private
129 Sub setFileTime()
130 Dim hFile = CreateFile(ToTCStr(FullPath), GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0)
131 If hFile = INVALID_HANDLE_VALUE Then
132 debug 'Exception
133 Exit Function
134 End If
135
136 If SetFileTime(hFile, m_CreationTime, m_LastAccessTime, m_LastWriteTime) = False Then
137 debug 'Exception
138 End If
139
140 CloseHandle(hFile)
141 End Sub
142End Class
143
144
145End Namespace
146End Namespace
Note: See TracBrowser for help on using the repository browser.