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

Last change on this file since 164 was 142, checked in by イグトランス (egtra), 18 years ago

Environment, OperatingSystem, Versionの追加、Unicode対応修正ほか

File size: 4.8 KB
RevLine 
[83]1Class FileSystemInfo
[84]2 m_CreationTime As FILETIME
3 m_LastAccessTime As FILETIME
4 m_LastWriteTime As FILETIME
5 m_FileAttributes As DWord
[83]6Protected
7 FullPath As String
8 OriginalPath As String
9Public
10 'Public Properties
11 Function Attributes() As FileAttributes
[84]12 Select Case m_FileAttributes
[83]13 Case FILE_ATTRIBUTE_ARCHIVE
[105]14 Return FileAttributes.Archive
[83]15 Case FILE_ATTRIBUTE_COMPRESSED
[105]16 Return FileAttributes.Compressed
[83]17 Case FILE_ATTRIBUTE_DIRECTORY
[105]18 Return FileAttributes.Directory
[83]19 Case FILE_ATTRIBUTE_ENCRYPTED
[105]20 Return FileAttributes.Encrypted
[83]21 Case FILE_ATTRIBUTE_HIDDEN
[105]22 Return FileAttributes.Hidden
[83]23 Case FILE_ATTRIBUTE_NORMAL
[105]24 Return FileAttributes.Normal
[83]25 Case FILE_ATTRIBUTE_OFFLINE
[105]26 Return FileAttributes.Offline
[83]27 Case FILE_ATTRIBUTE_READONLY
[105]28 Return FileAttributes.ReadOnly
[83]29 Case FILE_ATTRIBUTE_REPARSE_POINT
[105]30 Return FileAttributes.ReparsePoint
[83]31 Case FILE_ATTRIBUTE_SPARSE_FILE
[105]32 Return FileAttributes.SparseFile
[83]33 Case FILE_ATTRIBUTE_SYSTEM
[105]34 Return FileAttributes.System
[83]35 Case FILE_ATTRIBUTE_TEMPORARY
[105]36 Return FileAttributes.Temporary
[83]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
[105]47 Case FileAttributes.Archive
[83]48 attributes = FILE_ATTRIBUTE_ARCHIVE
[105]49 Case FileAttributes.Compressed
[83]50 attributes = FILE_ATTRIBUTE_COMPRESSED
[105]51 Case FileAttributes.Directory
[83]52 attributes = FILE_ATTRIBUTE_DIRECTORY
[105]53 Case FileAttributes.Hidden
[83]54 attributes = FILE_ATTRIBUTE_HIDDEN
[105]55 Case FileAttributes.Normal
[83]56 attributes = FILE_ATTRIBUTE_NORMAL
[105]57 Case FileAttributes.Offline
[83]58 attributes = FILE_ATTRIBUTE_OFFLINE
[105]59 Case FileAttributes.ReadOnly
[83]60 attributes = FILE_ATTRIBUTE_READONLY
[105]61 Case FileAttributes.System
[83]62 attributes = FILE_ATTRIBUTE_SYSTEM
[105]63 Case FileAttributes.Temporary
[83]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
[84]77 Return DateTime.FromFileTime(m_CreationTime)
[83]78 End Function
79
80 Sub CreationTime(ByRef value As DateTime)
[84]81 m_CreationTime = value.ToFileTimeUtc()
82 If setFileTime() = False Then
[83]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
[84]98 Return DateTime.FromFileTime(m_LastAccessTime)
[83]99 End Function
100
101 Sub LastAccessTime(ByRef value As DateTime)
[84]102 m_LastAccessTime = value.ToFileTimeUtc()
103 If setFileTime() = False Then
[83]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
[84]119 Return DateTime.FromFileTime(m_LastWriteTime)
[83]120 End Function
121
122 Sub LastWriteTime(ByRef value As DateTime)
[84]123 m_LastWriteTime = value.ToFileTimeUtc()
124 If setFileTime() = False Then
[83]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
[84]140 If m_FileAttributes = 0 Then
141 Return False
142 Else
143 Return True
144 End If
[83]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
[130]167 Virtual Sub Refresh()
[84]168 Dim data As WIN32_FIND_DATA
[142]169 Dim hFind = FindFirstFile(ToTCStr(FullPath), data)
[130]170 FindClose(hFind)
[84]171
172 m_FileAttributes = data.dwFileAttributes
173 m_CreationTime = data.ftCreationTime
174 m_LastAccessTime = data.ftLastAccessTime
175 m_LastWriteTime = data.ftLastWriteTime
[83]176 End Sub
177
178Private
[84]179 Function setFileTime() As Boolean
[142]180 Dim hFile = CreateFile(ToTCStr(FullPath), GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0)
[83]181 If hFile = INVALID_HANDLE_VALUE Then
[84]182 setFileTime = False
[83]183 Exit Function
184 End If
185
[84]186 If SetFileTime(hFile, m_CreationTime, m_LastAccessTime, m_LastWriteTime) Then
187 setFileTime = True
[83]188 Else
[84]189 setFileTime = False
[83]190 End If
[84]191
192 CloseHandle(hFile)
[83]193 End Function
[84]194End Class
Note: See TracBrowser for help on using the repository browser.