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

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

タイプミスを修正

File size: 4.9 KB
RevLine 
[271]1Namespace System
2Namespace IO
3
4
[83]5Class FileSystemInfo
[84]6 m_CreationTime As FILETIME
7 m_LastAccessTime As FILETIME
8 m_LastWriteTime As FILETIME
9 m_FileAttributes As DWord
[83]10Protected
11 FullPath As String
12 OriginalPath As String
13Public
14 'Public Properties
15 Function Attributes() As FileAttributes
[84]16 Select Case m_FileAttributes
[83]17 Case FILE_ATTRIBUTE_ARCHIVE
[105]18 Return FileAttributes.Archive
[83]19 Case FILE_ATTRIBUTE_COMPRESSED
[105]20 Return FileAttributes.Compressed
[83]21 Case FILE_ATTRIBUTE_DIRECTORY
[105]22 Return FileAttributes.Directory
[83]23 Case FILE_ATTRIBUTE_ENCRYPTED
[105]24 Return FileAttributes.Encrypted
[83]25 Case FILE_ATTRIBUTE_HIDDEN
[105]26 Return FileAttributes.Hidden
[83]27 Case FILE_ATTRIBUTE_NORMAL
[105]28 Return FileAttributes.Normal
[83]29 Case FILE_ATTRIBUTE_OFFLINE
[105]30 Return FileAttributes.Offline
[83]31 Case FILE_ATTRIBUTE_READONLY
[105]32 Return FileAttributes.ReadOnly
[83]33 Case FILE_ATTRIBUTE_REPARSE_POINT
[105]34 Return FileAttributes.ReparsePoint
[83]35 Case FILE_ATTRIBUTE_SPARSE_FILE
[105]36 Return FileAttributes.SparseFile
[83]37 Case FILE_ATTRIBUTE_SYSTEM
[105]38 Return FileAttributes.System
[83]39 Case FILE_ATTRIBUTE_TEMPORARY
[105]40 Return FileAttributes.Temporary
[83]41 Case Else
42 'Exception
43 Debug
44 End Select
45 End Function
46
47 Sub Attributes(ByRef value As FileAttributes)
48 Dim attributes As DWord
49 Select Case value
[105]50 Case FileAttributes.Archive
[83]51 attributes = FILE_ATTRIBUTE_ARCHIVE
[105]52 Case FileAttributes.Compressed
[83]53 attributes = FILE_ATTRIBUTE_COMPRESSED
[105]54 Case FileAttributes.Directory
[83]55 attributes = FILE_ATTRIBUTE_DIRECTORY
[105]56 Case FileAttributes.Hidden
[83]57 attributes = FILE_ATTRIBUTE_HIDDEN
[105]58 Case FileAttributes.Normal
[83]59 attributes = FILE_ATTRIBUTE_NORMAL
[105]60 Case FileAttributes.Offline
[83]61 attributes = FILE_ATTRIBUTE_OFFLINE
[105]62 Case FileAttributes.ReadOnly
[83]63 attributes = FILE_ATTRIBUTE_READONLY
[105]64 Case FileAttributes.System
[83]65 attributes = FILE_ATTRIBUTE_SYSTEM
[105]66 Case FileAttributes.Temporary
[83]67 attributes = FILE_ATTRIBUTE_TEMPORARY
68 Case Else
69 'Exception
70 Exit Sub
71 End Select
72
73 If SetFileAttributes(FullPath, attributes) = FALSE Then
74 'Exception
75 Debug
76 End If
77 End Sub
78
79 Function CreationTime() As DateTime
[84]80 Return DateTime.FromFileTime(m_CreationTime)
[83]81 End Function
82
83 Sub CreationTime(ByRef value As DateTime)
[84]84 m_CreationTime = value.ToFileTimeUtc()
85 If setFileTime() = False Then
[83]86 'Exception
87 debug
88 End If
89 End Sub
90
91 Function CreationTimeUtc() As DateTime
92 Dim date = CreationTime As DateTime
93 Return date.ToUniversalTime()
94 End Function
95
96 Sub CreationTimeUtc(ByRef value As DateTime)
97 CreationTime = value
98 End Sub
99
100 Function LastAccessTime() As DateTime
[84]101 Return DateTime.FromFileTime(m_LastAccessTime)
[83]102 End Function
103
104 Sub LastAccessTime(ByRef value As DateTime)
[84]105 m_LastAccessTime = value.ToFileTimeUtc()
106 If setFileTime() = False Then
[83]107 'Exception
108 debug
109 End If
110 End Sub
111
112 Function LastAccessTimeUtc() As DateTime
113 Dim date = LastAccessTime As DateTime
114 Return date.ToUniversalTime()
115 End Function
116
117 Sub LastAccessTimeUtc(ByRef value As DateTime)
118 LastAccessTime = value
119 End Sub
120
121 Function LastWriteTime() As DateTime
[84]122 Return DateTime.FromFileTime(m_LastWriteTime)
[83]123 End Function
124
125 Sub LastWriteTime(ByRef value As DateTime)
[84]126 m_LastWriteTime = value.ToFileTimeUtc()
127 If setFileTime() = False Then
[83]128 'Exception
129 debug
130 End If
131 End Sub
132
133 Function LastWriteTimeUtc() As DateTime
134 Dim date = LastWriteTime As DateTime
135 Return date.ToUniversalTime()
136 End Function
137
138 Sub LastWriteTimeUtc(ByRef value As DateTime)
139 LastWriteTime = value
140 End Sub
141
142 Function Exists() As Boolean
[84]143 If m_FileAttributes = 0 Then
144 Return False
145 Else
146 Return True
147 End If
[83]148 End Function
149
150 Function Extension() As String
151 Return Path.GetExtension(FullPath)
152 End Function
153
154 Function FullName() As String
155 Return FullPath
156 End Function
157
158 Function Name() As String
159 Return Path.GetFileName(FullPath)
160 End Function
161
162 'Public Methods
163 Virtual Sub Delete()
164 If DeleteFile(FullPath) = FALSE Then
165 'Exception
166 debug
167 End If
168 End Sub
169
[130]170 Virtual Sub Refresh()
[84]171 Dim data As WIN32_FIND_DATA
[142]172 Dim hFind = FindFirstFile(ToTCStr(FullPath), data)
[130]173 FindClose(hFind)
[84]174
175 m_FileAttributes = data.dwFileAttributes
176 m_CreationTime = data.ftCreationTime
177 m_LastAccessTime = data.ftLastAccessTime
178 m_LastWriteTime = data.ftLastWriteTime
[83]179 End Sub
180
181Private
[84]182 Function setFileTime() As Boolean
[142]183 Dim hFile = CreateFile(ToTCStr(FullPath), GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0)
[83]184 If hFile = INVALID_HANDLE_VALUE Then
[84]185 setFileTime = False
[83]186 Exit Function
187 End If
188
[84]189 If SetFileTime(hFile, m_CreationTime, m_LastAccessTime, m_LastWriteTime) Then
190 setFileTime = True
[83]191 Else
[84]192 setFileTime = False
[83]193 End If
[84]194
195 CloseHandle(hFile)
[83]196 End Function
[271]197End Class
198
199
200End Namespace
201End Namespace
Note: See TracBrowser for help on using the repository browser.