Changeset 84 for Include/Classes/System/IO/FileSystemInfo.ab
- Timestamp:
- Feb 3, 2007, 12:35:13 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Include/Classes/System/IO/FileSystemInfo.ab
r83 r84 1 1 Class FileSystemInfo 2 m_CreationTime As FILETIME 3 m_LastAccessTime As FILETIME 4 m_LastWriteTime As FILETIME 5 m_FileAttributes As DWord 2 6 Protected 3 7 FullPath As String … … 6 10 'Public Properties 7 11 Function Attributes() As FileAttributes 8 Dim data As WIN32_FIND_DATA 9 If getFindFile(data) = False Then 10 'Exception 11 Debug 12 Exit Function 13 End If 14 Select Case data.dwFileAttributes 12 Select Case m_FileAttributes 15 13 Case FILE_ATTRIBUTE_ARCHIVE 16 14 Return Archive … … 77 75 78 76 Function CreationTime() As DateTime 79 Dim data As WIN32_FIND_DATA 80 If getFindFile(data) = False Then 81 'Exception 82 Debug 83 End If 84 Return DateTime.FromFileTime(data.ftCreationTime) 77 Return DateTime.FromFileTime(m_CreationTime) 85 78 End Function 86 79 87 80 Sub CreationTime(ByRef value As DateTime) 88 If setFileTime(_CreationTime, value) = FALSE Then 81 m_CreationTime = value.ToFileTimeUtc() 82 If setFileTime() = False Then 89 83 'Exception 90 84 debug … … 102 96 103 97 Function LastAccessTime() As DateTime 104 Dim data As WIN32_FIND_DATA 105 If getFindFile(data) = False Then 106 'Exception 107 Debug 108 End If 109 Return DateTime.FromFileTime(data.ftLastAccessTime) 98 Return DateTime.FromFileTime(m_LastAccessTime) 110 99 End Function 111 100 112 101 Sub LastAccessTime(ByRef value As DateTime) 113 If setFileTime(_LastAccessTime, value) = FALSE Then 102 m_LastAccessTime = value.ToFileTimeUtc() 103 If setFileTime() = False Then 114 104 'Exception 115 105 debug … … 127 117 128 118 Function LastWriteTime() As DateTime 129 Dim data As WIN32_FIND_DATA 130 If getFindFile(data) = False Then 131 'Exception 132 Debug 133 End If 134 Return DateTime.FromFileTime(data.ftLastWriteTime) 119 Return DateTime.FromFileTime(m_LastWriteTime) 135 120 End Function 136 121 137 122 Sub LastWriteTime(ByRef value As DateTime) 138 If setFileTime(_LastWriteTime, value) = FALSE Then 123 m_LastWriteTime = value.ToFileTimeUtc() 124 If setFileTime() = False Then 139 125 'Exception 140 126 debug … … 152 138 153 139 Function Exists() As Boolean 154 Dim data As WIN32_FIND_DATA 155 Return getFindFile(data) 140 If m_FileAttributes = 0 Then 141 Return False 142 Else 143 Return True 144 End If 156 145 End Function 157 146 … … 176 165 End Sub 177 166 178 '未実装179 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 180 177 End Sub 181 178 182 179 Private 183 Function getFindFile(ByRef data As WIN32_FIND_DATA) As Boolean 184 Dim hFind As HANDLE 185 hFind = FindFirstFile(FullPath, data) 186 If hFind = INVALID_HANDLE_VALUE Then 187 Return False 188 Else 189 CloseHandle(hFind) 190 Return True 191 End If 192 End Function 193 194 '任意のファイル日時を変更する。flagsに、どの日時を変更するかを指定する。 195 Function setFileTime(flags As _FileTimeType, ByRef value As DateTime) As Boolean 180 Function setFileTime() As Boolean 196 181 Dim hFile As HANDLE 197 182 hFile = CreateFile(FullPath, GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0) 198 183 If hFile = INVALID_HANDLE_VALUE Then 199 setFileTime = F ALSE184 setFileTime = False 200 185 Exit Function 201 186 End If 202 187 203 Dim fileTime As FILETIME 204 Dim results As Long 205 fileTime = value.ToFileTimeUtc() 206 Select Case flags 207 Case _CreationTime 208 results = SetFileTime(hFile, fileTime, ByVal 0, ByVal 0) 209 Case _LastAccessTime 210 results = SetFileTime(hFile, ByVal 0, fileTime, ByVal 0) 211 Case _LastWriteTime 212 results = SetFileTime(hFile, ByVal 0, ByVal 0, fileTime) 213 End Select 188 If SetFileTime(hFile, m_CreationTime, m_LastAccessTime, m_LastWriteTime) Then 189 setFileTime = True 190 Else 191 setFileTime = False 192 End If 193 214 194 CloseHandle(hFile) 215 216 If results Then217 Return True218 Else219 Return False220 End If221 195 End Function 222 196 End Class 223 224 Const Enum _FileTimeType225 _CreationTime226 _LastAccessTime227 _LastWriteTime228 End Enum
Note:
See TracChangeset
for help on using the changeset viewer.