avkokin said:
There is one document. I want to change of date of create it. Can I
modify the property "Creation Date" for this document? E.g, to some
predetermined date? How?
You're talking about the "Date Created" as shown in Windows Explorer (or its
File-Properties dialogs)? If so, you'll want to use the SetFileTime API, which can
also modify the "Date Modified" and "Date Last Accessed" as well. Something like
this:
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal
lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long,
lpSecurityAttributes As Any, ByVal dwCreationDisposition As Long, ByVal
dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function SetFileTime Lib "kernel32" (ByVal hFile As Long,
lpCreationTime As Any, lpLastAccessTime As Any, lpLastWriteTime As Any) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As
Long
' API structures.
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
' Enumerated constants
Private Enum FileTimes
ftCreationTime = 0
ftLastAccessTime = 1
ftLastWriteTime = 2
End Enum
Private Function SetTime(FileName As String, NewTime As Double, WhichTime As
FileTimes) As Boolean
Dim ft As FILETIME
Dim hFile As Long
' Bail if no file exists.
If FileExists(FileName) = False Then Exit Function
' Convert passed time (presumably local) to UTC.
ft = DoubleToFileTime(NewTime, True)
' Get a handle on existing file so we can change times.
hFile = CreateFile(FileName, _
GENERIC_READ Or GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, _
ByVal 0&, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0)
' If we were able to open file, change it's timestamp.
If hFile <> INVALID_HANDLE_VALUE Then
Select Case WhichTime
Case ftCreationTime
SetTime = SetFileTime(hFile, ft, ByVal 0&, ByVal 0&)
Case ftLastAccessTime
SetTime = SetFileTime(hFile, ByVal 0&, ft, ByVal 0&)
Case ftLastWriteTime
SetTime = SetFileTime(hFile, ByVal 0&, ByVal 0&, ft)
End Select
Call CloseHandle(hFile)
End If
End Function
Private Function DoubleToFileTime(ftDbl As Double, Optional Universalize As
Boolean = True) As FILETIME
Dim ft As FILETIME
Dim st As SYSTEMTIME
' Convert double to systemtime structure.
With st
.wYear = Year(ftDbl)
.wMonth = Month(ftDbl)
.wDay = Day(ftDbl)
.wDayOfWeek = WeekDay(ftDbl) - 1
.wHour = Hour(ftDbl)
.wMinute = Minute(ftDbl)
.wSecond = Second(ftDbl)
End With
' Convert systemtime to filetime structure.
Call SystemTimeToFileTime(st, ft)
' Convert local time to UTC time, if requested.
If Universalize Then
Call LocalFileTimeToFileTime(ft, DoubleToFileTime)
Else
DoubleToFileTime = ft
End If
End Function
Etc, etc, etc... All this and more, ready-to-run(!), at
http://vb.mvps.org/samples/FileInfo