Condividi tramite

Data creazione database modificata

Anonimo
2015-12-04T16:00:26+00:00

Buonasera a tutta la Community,

la mia domanda è, credo, tanto semplice quanto "strana";

è possibile modificare la data di creazione di un database?

Per essere più preciso, in FILE - Informazioni ho letto le statistiche di uno dei miei database e mi sono accorto

che riporta una data "non veritiera". Nella fattispecie la data riportata è 1/1/2007 . Io non sono l'utilizzatore del db, l'ho solo

creato (anche grazie agli aiuti che mi avete dato) ma ho la certezza che chi lo utilizza non sia

nelle condizioni di modificare un'informazione così "particolare".

Mi potreste spiegare come è possibile e se si può cambiare la data di creazione?

Vi ringrazio anticipatamente.

Fausto.

Microsoft 365 e Office | Access | Per la casa | Windows

Domanda bloccata. Questa domanda è stata eseguita dalla community del supporto tecnico Microsoft. È possibile votare se è utile, ma non è possibile aggiungere commenti o risposte o seguire la domanda.

0 commenti Nessun commento

6 risposte

Ordina per: Più utili
  1. Anonimo
    2015-12-05T10:06:39+00:00

    Buongiorno David, come promesso stanotte, ho guardato i due link che mi hai suggerito. Ho anche fatto la prova a copiare il file del database in un altro percorso ma la data, presente nelle statistiche del menu FILE - Informazioni, rimane 1/1/2007. Ripeto, il database l'ho "creato" solo 2 mesi fa' (circa). Si modificano le date Ultima modifica e ultimo Accesso ma la data di creazione rimane 1/1/2007 . E ciò è impossibile....

    Ho provato anche a creare un nuovo db vuoto e a copiargli tutte le tabelle, query, form e report. Ma anche in questo caso la data di creazione, modifica e accesso è la data attuale (oggi) ma non quella del giorno in cui ho creato il db.....

    Non che sia di vitale importanza, ma vorrei capirci....

    Ti e vi ringrazio ancora per il vostro aiuto.

    Saluti.

    Fausto.

    La risposta è stata utile?

    0 commenti Nessun commento
  2. Anonimo
    2015-12-04T22:21:32+00:00

    Intanto ringrazio tutti e tre per i vostri interventi. Considerata l'ora non riesco a leggere con attenzione i link di David o il codice di Sandro. Già è difficile nelle ore diurne figuriamoci la notte... hihihi domani li guarderò con la giusta attenzione.

    Giorgio è proprio quella la data che ho trovato modificata. La cosa che mi stranizza è che il database l'ho iniziato a fine settembre e concluso non più di 15 giorni fa' . La data invece "afferma" che è stato creato il 1/1/2007 .

    Boh... ripeto, a mente serena domani mi rileggo tutti i post e i link e cerco di togliermi i dubbi che mi rimangono.

    Grazie a tutti per il vostro aiuto. Buonanotte.

    Fausto

    La risposta è stata utile?

    0 commenti Nessun commento
  3. Anonimo
    2015-12-04T20:13:49+00:00

    Ciao Sandro, ciao David

    credo che Fausto non si riferisca alla data di creazione del file che può cambiare con la semplice copia in un'altra cartella, ma della data creazione del database che è una proprietà dei databases di access

    CurrentDb.Containers("Databases").Documents("SummaryInfo").Properties ("DateCreated")

    quella che appunto si visualizza premendo File-->Visualizza e modifica le proprietà del database-->Scheda Statistiche

    l'unico modo che mi viene in mente per cambiare la data di creazione database è quella di creare un nuovo Db e importare in esso tutti gli oggetti dal db sorgente.

    Ciao

    Giorgio Rancati

    La risposta è stata utile?

    0 commenti Nessun commento
  4. Anonimo
    2015-12-04T19:19:09+00:00

    ciao Fausto,

    non è farina del mio sacco...non ricordo esattamente dove l'ho presa...

    sarebbe forse da curare un po'....

    guarda l'ultima sub per le personalizzazioni.

    ciao, Sandro.

    Option Explicit

    Option Compare Database

    '''''''''''''''''''''''''''''''''''

    Private Const NULL_LONG As Long = 0&

    Private Const C_ERROR As Long = -1&

    Private Const OPEN_EXISTING = &H3

    Private Const FILE_SHARE_READ = &H1

    Private Const FILE_SHARE_WRITE = &H2

    Private Const CREATE_ALWAYS = &H2

    Private Const OPEN_ALWAYS = &H4

    Private Const INVALID_HANDLE_VALUE = -1

    Private Const ERROR_ALREADY_EXISTS = &HB7

    Private Const GENERIC_ALL = &H10000000

    Private Const GENERIC_EXECUTE = &H20000000

    Private Const GENERIC_READ = &H80000000

    Private Const GENERIC_WRITE = &H40000000

    Public Const TIME_ZONE_ID_UNKNOWN = 0

    Public Const TIME_ZONE_ID_STANDARD = 1

    Public Const TIME_ZONE_ID_DAYLIGHT = 2

    Public Const TIME_ZONE_ID_INVALID = -1

    Public Enum FileDateToProcess

        FileDateCreate = 1

        FileDateLastAccess = 2

        FileDateLastModified = 3

    End Enum

    Public Type FileTime

        dwLowDateTime As Long

        dwHighDateTime As Long

    End Type

    Public Type SYSTEMTIME

        wYear As Integer

        wMonth As Integer

        wDayOfWeek As Integer

        wDay As Integer

        wHour As Integer

        wMinute As Integer

        wSecond As Integer

        wMilliseconds As Integer

    End Type

    Public Type TIME_ZONE_INFORMATION

        Bias As Long

        StandardName(0 To 31) As Integer

        StandardDate As SYSTEMTIME

        StandardBias As Long

        DaylightName(0 To 31) As Integer

        DaylightDate As SYSTEMTIME

        DaylightBias As Long

    End Type

    Private Const FORMAT_MESSAGE_ALLOCATE_BUFFER = &H100

    Private Const FORMAT_MESSAGE_ARGUMENT_ARRAY = &H2000

    Private Const FORMAT_MESSAGE_FROM_HMODULE = &H800

    Private Const FORMAT_MESSAGE_FROM_STRING = &H400

    Private Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000

    Private Const FORMAT_MESSAGE_MAX_WIDTH_MASK = &HFF

    Private Const FORMAT_MESSAGE_IGNORE_INSERTS = &H200

    Private Const FORMAT_MESSAGE_TEXT_LEN = &HA0 ' from ERRORS.H C++ include file.

    Private Declare PtrSafe Function LocalFileTimeToFileTime Lib "kernel32" _

        (lpLocalFileTime As FileTime, _

         lpFileTime As FileTime) As Long

    Private Declare PtrSafe Function FileTimeToLocalFileTime Lib "kernel32" ( _

        lpFileTime As FileTime, _

        lpLocalFileTime As FileTime) As Long

    Private Declare PtrSafe Function SystemTimeToFileTime Lib "kernel32" _

        (lpSystemTime As SYSTEMTIME, _

        lpFileTime As FileTime) As Long

    Private Declare PtrSafe Function CreateFile Lib "kernel32" Alias "CreateFileA" _

        (ByVal lpFilename As String, _

        ByVal dwDesiredAccess As Long, _

        ByVal dwShareMode As Long, _

        ByVal lpSecurityAttributes As Long, _

        ByVal dwCreationDisposition As Long, _

        ByVal dwFlagsAndAttributes As Long, _

        ByVal hTemplateFile As Long) As Long

    Private Declare PtrSafe Function CloseHandle Lib "kernel32" _

       (ByVal hObject As Long) As Long

    Private Declare PtrSafe Function SetFileTimeCreate Lib "kernel32" Alias "SetFileTime" _

       (ByVal hFile As Long, _

        CreateTime As FileTime, _

        ByVal LastAccessTime As Long, _

        ByVal LastModified As Long) As Long

    Private Declare PtrSafe Function SetFileTimeLastAccess Lib "kernel32" Alias "SetFileTime" _

       (ByVal hFile As Long, _

        ByVal CreateTime As Long, _

        LastAccessTime As FileTime, _

        ByVal LastModified As Long) As Long

    Private Declare PtrSafe Function SetFileTimeLastModified Lib "kernel32" Alias "SetFileTime" _

       (ByVal hFile As Long, _

        ByVal CreateTime As Long, _

        ByVal LastAccessTime As Long, _

        LastModified As FileTime) As Long

    Public Function GetSystemErrorMessageText(ErrorNumber As Long) As String

    Dim ErrorText As String

    Dim TextLen As Long

    Dim FormatMessageResult As Long

    Dim LangID As Long

    ' initialize the variables

    LangID = 0&  'default language

    ErrorText = String$(FORMAT_MESSAGE_TEXT_LEN, vbNullChar)

    TextLen = Len(ErrorText)

    On Error Resume Next

    ' Call FormatMessage to get the text of the error message

    ' associated with ErrorNumber.

    FormatMessageResult = FormatMessage( _

                    dwFlags:=FORMAT_MESSAGE_FROM_SYSTEM Or _

                             FORMAT_MESSAGE_IGNORE_INSERTS, _

                    lpSource:=0&, _

                    dwMessageId:=ErrorNumber, _

                    dwLanguageId:=0&, _

                    lpBuffer:=ErrorText, _

                    nSize:=TextLen, _

                    Arguments:=0&)

    On Error GoTo 0

    If FormatMessageResult = 0& Then

        MsgBox "An error occurred with the FormatMessage" & _

            " API functiopn call. Error: " & _

            CStr(Err.LastDllError) & _

            " Hex(" & Hex(Err.LastDllError) & ")."

        GetSystemErrorMessageText = vbNullString

        Exit Function

    End If

    If FormatMessageResult > 0 Then

        ErrorText = Left$(ErrorText, FormatMessageResult)

        GetSystemErrorMessageText = ErrorText

    Else

        GetSystemErrorMessageText = "NO ERROR DESCRIPTION AVAILABLE"

    End If

    End Function

    Public Function SetFileDateTime(FileName As String, _

        FileDateTime As Double, WhichDateToChange As FileDateToProcess, _

        Optional NoGMTConvert As Boolean = False) As Boolean

    Dim FileHandle As Long

    Dim Res As Long

    Dim ErrNum As Long

    Dim ErrText As String

    Dim tFileTime As FileTime

    Dim tLocalTime As FileTime

    Dim tSystemTime As SYSTEMTIME

    If Dir(FileName) = vbNullString Then

        SetFileDateTime = False

        Exit Function

    End If

    With tSystemTime

        .wYear = Year(FileDateTime)

        .wMonth = Month(FileDateTime)

        .wDay = Day(FileDateTime)

        .wDayOfWeek = Weekday(FileDateTime) - 1

        .wHour = Hour(FileDateTime)

        .wMinute = Minute(FileDateTime)

        .wSecond = Second(FileDateTime)

    End With

    Res = SystemTimeToFileTime(lpSystemTime:=tSystemTime, lpFileTime:=tLocalTime)

    If Res = 0 Then

        ErrNum = Err.LastDllError

        ErrText = GetSystemErrorMessageText(ErrorNumber:=ErrNum)

        Debug.Print "Error from SystemTimeToFileTime" & vbCrLf & _

            "Err:  " & CStr(ErrNum) & vbCrLf & _

            "Desc: " & ErrText

        SetFileDateTime = False

        Exit Function

    End If

    If NoGMTConvert = False Then

        Res = LocalFileTimeToFileTime(lpLocalFileTime:=tLocalTime, lpFileTime:=tFileTime)

    Else

        tFileTime.dwHighDateTime = tLocalTime.dwHighDateTime

        tFileTime.dwLowDateTime = tLocalTime.dwLowDateTime

        Res = 2

    End If

    If Res = 0 Then

        ''''''''''''''''''''''

        ' An error occurred.

        ''''''''''''''''''''''syst

        ErrNum = Err.LastDllError

        ErrText = GetSystemErrorMessageText(ErrorNumber:=ErrNum)

        Debug.Print "Error from LocalFileTimeToFileTime" & vbCrLf & _

            "Err:  " & CStr(ErrNum) & vbCrLf & _

            "Desc: " & ErrText

        SetFileDateTime = False

        Exit Function

    End If

    FileHandle = CreateFile(lpFilename:=FileName, _

                            dwDesiredAccess:=GENERIC_WRITE, _

                            dwShareMode:=FILE_SHARE_READ Or FILE_SHARE_WRITE, _

                            lpSecurityAttributes:=ByVal 0&, _

                            dwCreationDisposition:=OPEN_EXISTING, _

                            dwFlagsAndAttributes:=0, _

                            hTemplateFile:=0)

    If FileHandle = INVALID_HANDLE_VALUE Then

        ErrNum = Err.LastDllError

        ErrText = GetSystemErrorMessageText(ErrorNumber:=ErrNum)

        Debug.Print "Error from CreateFile" & vbCrLf & _

            "Err:  " & CStr(ErrNum) & vbCrLf & _

            "Desc: " & ErrText

        SetFileDateTime = False

        Exit Function

    End If

    Select Case WhichDateToChange

        Case FileDateCreate

            Res = SetFileTimeCreate( _

                hFile:=FileHandle, _

                CreateTime:=tFileTime, _

                LastAccessTime:=NULL_LONG, _

                LastModified:=NULL_LONG)

            If Res = 0 Then

                ErrNum = Err.LastDllError

                ErrText = GetSystemErrorMessageText(ErrNum)

                Debug.Print "Error With SetFileTimeCreate:" & vbCrLf & _

                            "Err:  " & CStr(ErrNum) & vbCrLf & _

                            "Desc: " & ErrText

                SetFileDateTime = False

                Exit Function

            End If

        Case FileDateLastAccess

            Res = SetFileTimeLastAccess( _

                hFile:=FileHandle, _

                CreateTime:=NULL_LONG, _

                LastAccessTime:=tFileTime, _

                LastModified:=NULL_LONG)

            If Res = 0 Then

                ErrNum = Err.LastDllError

                ErrText = GetSystemErrorMessageText(ErrNum)

                Debug.Print "Error With SetFileTimeLastAccess:" & vbCrLf & _

                            "Err:  " & CStr(ErrNum) & vbCrLf & _

                            "Desc: " & ErrText

                SetFileDateTime = False

                Exit Function

            End If

        Case FileDateLastModified

            Res = SetFileTimeLastModified( _

                hFile:=FileHandle, _

                CreateTime:=NULL_LONG, _

                LastAccessTime:=NULL_LONG, _

                LastModified:=tFileTime)

            If Res = 0 Then

                ErrNum = Err.LastDllError

                ErrText = GetSystemErrorMessageText(ErrNum)

                Debug.Print "Error With SetFileTimeLastModified:" & vbCrLf & _

                            "Err:  " & CStr(ErrNum) & vbCrLf & _

                            "Desc: " & ErrText

                SetFileDateTime = False

                Exit Function

            End If

        Case Else

            Debug.Print "Invalid value for WhichDateToChange: " & CStr(WhichDateToChange)

            CloseHandle FileHandle

            SetFileDateTime = False

            Exit Function

    End Select

    CloseHandle FileHandle

    SetFileDateTime = True

    End Function

    Public Function GetFileDateTime(FileName As String, _

            WhichDateToGet As FileDateToProcess, _

            Optional NoGMTConvert As Boolean = False) As Double

    Dim FileHandle As Long

    Dim Res As Long

    Dim ErrNum As Long

    Dim ErrText As String

    Dim tFileTime As FileTime

    Dim tLocalTime As FileTime

    Dim tSystemTime As SYSTEMTIME

    Dim ResultTime As Double

    Const C_ERROR As Double = -1

    ''''''''''''''''''''''''''''''''''''

    ' Ensure the file exists.

    ''''''''''''''''''''''''''''''''''''

    If Dir(FileName) = vbNullString Then

        GetFileDateTime = C_ERROR

        Exit Function

    End If

    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    ' Here, we use CreateFile to open the existing file

    ' named in FileName.  The OPEN_EXISTING flag indicates

    ' that we are opening an existing flag.

    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    FileHandle = CreateFile(lpFilename:=FileName, dwDesiredAccess:=GENERIC_READ, _

        dwShareMode:=FILE_SHARE_READ Or FILE_SHARE_WRITE, lpSecurityAttributes:=ByVal 0&, _

          dwCreationDisposition:=OPEN_EXISTING, dwFlagsAndAttributes:=0, hTemplateFile:=0)

    If FileHandle = INVALID_HANDLE_VALUE Then

        ''''''''''''''''''''''

        ' An error occurred.

        ''''''''''''''''''''''

        ErrNum = Err.LastDllError

        ErrText = GetSystemErrorMessageText(ErrorNumber:=ErrNum)

        Debug.Print "Error from SystemTimeToFileTime" & vbCrLf & _

            "Err:  " & CStr(ErrNum) & vbCrLf & _

            "Desc: " & ErrText

        GetFileDateTime = C_ERROR

        Exit Function

    End If

    Select Case WhichDateToGet

        Case FileDateCreate

            '''''''''''''''''''''''''''''''''''''''''''''''''''

            ' Call the GetFileTimeCreate flavor of GetFileTime.

            '''''''''''''''''''''''''''''''''''''''''''''''''''

            Res = GetFileTimeCreate( _

                hFile:=FileHandle, _

                CreateTime:=tFileTime, _

                LastAccessTime:=NULL_LONG, _

                LastModified:=NULL_LONG)

            If Res = 0 Then

                ErrNum = Err.LastDllError

                ErrText = GetSystemErrorMessageText(ErrNum)

                Debug.Print "Error With GetFileTimeCreate (GetFileTime):" & vbCrLf & _

                            "Err:  " & CStr(ErrNum) & vbCrLf & _

                            "Desc: " & ErrText

                GetFileDateTime = C_ERROR

                Exit Function

            End If

        Case FileDateLastAccess

            '''''''''''''''''''''''''''''''''''''''''''''''''''

            ' Call the GetFileTimeLastAccess flavor of GetFileTime.

            '''''''''''''''''''''''''''''''''''''''''''''''''''

            Res = GetFileTimeLastAccess( _

                hFile:=FileHandle, _

                CreateTime:=NULL_LONG, _

                LastAccessTime:=tFileTime, _

                LastModified:=NULL_LONG)

            If Res = 0 Then

                ErrNum = Err.LastDllError

                ErrText = GetSystemErrorMessageText(ErrNum)

                Debug.Print "Error With SetFileTimeLastAccess (SetFileTime):" & vbCrLf & _

                            "Err:  " & CStr(ErrNum) & vbCrLf & _

                            "Desc: " & ErrText

                GetFileDateTime = C_ERROR

                Exit Function

            End If

        Case FileDateLastModified

            '''''''''''''''''''''''''''''''''''''''''''''''''''

            ' Call the GetFileTimeLastModified flavor of GetFileTime.

            '''''''''''''''''''''''''''''''''''''''''''''''''''

            Res = GetFileTimeLastModified( _

                hFile:=FileHandle, _

                CreateTime:=NULL_LONG, _

                LastAccessTime:=NULL_LONG, _

                LastModified:=tFileTime)

            If Res = 0 Then

                ErrNum = Err.LastDllError

                ErrText = GetSystemErrorMessageText(ErrNum)

                Debug.Print "Error With GetFileTimeLastModified (GetFileTime):" & vbCrLf & _

                            "Err:  " & CStr(ErrNum) & vbCrLf & _

                            "Desc: " & ErrText

                GetFileDateTime = C_ERROR

                Exit Function

            End If

        Case Else

            ''''''''''''''''''''''''''''''''''''''

            ' Invalid value for WhichDateToChange.

            ''''''''''''''''''''''''''''''''''''''

            Debug.Print "Invalid value for WhichDateToChange: " & CStr(WhichDateToGet)

            CloseHandle FileHandle

            GetFileDateTime = C_ERROR

            Exit Function

    End Select

    ''''''''''''''''''''''''''''''''''''''''''''''

    ' Convert the FileTime (GMT) to LocalFileTime)

    ' if NoGMTConvert is omitted or False.

    ''''''''''''''''''''''''''''''''''''''''''''''

    If NoGMTConvert = False Then

        Res = FileTimeToLocalFileTime(lpFileTime:=tFileTime, lpLocalFileTime:=tLocalTime)

    Else

        '''''''''''''''''''''''''''''''''''''''''''''''''''

        ' We are NOT converting from GMT.

        '''''''''''''''''''''''''''''''''''''''''''''''''''

        tLocalTime.dwHighDateTime = tFileTime.dwHighDateTime

        tLocalTime.dwLowDateTime = tFileTime.dwLowDateTime

        Res = 2

    End If

    If Res = 0 Then

        '''''''''''''''''''''

        ' An error occurred

        '''''''''''''''''''''

        ErrNum = Err.LastDllError

        ErrText = GetSystemErrorMessageText(ErrNum)

        Debug.Print "Error With FileTimeToLocalFileTime:" & vbCrLf & _

                    "Err:  " & CStr(ErrNum) & vbCrLf & _

                    "Desc: " & ErrText

        GetFileDateTime = C_ERROR

        Exit Function

    End If

    ''''''''''''''''''''''''''''''''''''

    ' Convert the FileTime to SystemTime

    ''''''''''''''''''''''''''''''''''''

    Res = FileTimeToSystemTime(lpFileTime:=tLocalTime, lpSystemTime:=tSystemTime)

    If Res = 0 Then

        '''''''''''''''''''''

        ' An error occurred

        '''''''''''''''''''''

        ErrNum = Err.LastDllError

        ErrText = GetSystemErrorMessageText(ErrNum)

        Debug.Print "Error With FileTimeToSystemTime:" & vbCrLf & _

                    "Err:  " & CStr(ErrNum) & vbCrLf & _

                    "Desc: " & ErrText

        GetFileDateTime = C_ERROR

        Exit Function

    End If

    '''''''''''''''''''''''''''''''''

    ' Convert from SystemTime to VB

    ' Time value.

    '''''''''''''''''''''''''''''''''

    ResultTime = DateSerial(tSystemTime.wYear, tSystemTime.wMonth, tSystemTime.wDay) + _

                 TimeSerial(tSystemTime.wHour, tSystemTime.wMinute, tSystemTime.wSecond)

    '''''''''''''''''''''''''''''''''

    ' Close the file and return True.

    '''''''''''''''''''''''''''''''''

    CloseHandle FileHandle

    GetFileDateTime = ResultTime

    End Function

    'Public Function GetFileDateTimeAsFILETIME(FileName As String, _

      WhichDateToGet As FileDateToProcess, FTime As FileTime, _

      Optional ConvertFromGMT As Boolean = False) As Boolean

    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    ' GetFileTimeAsFILETIME

    ' This function populates the FTime FILETIME structure with the file data

    ' specified by WhichDateToGet for the file FileName. Note that there

    ' is no conversion from GMT Time here

    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    Dim FileHandle As Long

    Dim ErrNum As Long

    Dim ErrText As String

    Dim tFileTime As FileTime

    Dim Res As Long

    Dim tLocalFileTime As FileTime

    Const C_ERROR As Boolean = False

    ''''''''''''''''''''''''''''''''''''

    ' Ensure the file exists.

    ''''''''''''''''''''''''''''''''''''

    If Dir(FileName) = vbNullString Then

        GetFileDateTimeAsFILETIME = C_ERROR

        Exit Function

    End If

    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    ' Here, we use CreateFile to open the existing file

    ' named in FileName.  The OPEN_EXISTING flag indicates

    ' that we are opening an existing flag.

    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    FileHandle = CreateFile(lpFilename:=FileName, dwDesiredAccess:=GENERIC_READ, _

        dwShareMode:=FILE_SHARE_READ Or FILE_SHARE_WRITE, lpSecurityAttributes:=ByVal 0&, _

          dwCreationDisposition:=OPEN_EXISTING, dwFlagsAndAttributes:=0, hTemplateFile:=0)

    If FileHandle = INVALID_HANDLE_VALUE Then

        ''''''''''''''''''''''

        ' An error occurred.

        ''''''''''''''''''''''

        ErrNum = Err.LastDllError

        ErrText = GetSystemErrorMessageText(ErrorNumber:=ErrNum)

        Debug.Print "Error from SystemTimeToFileTime" & vbCrLf & _

            "Err:  " & CStr(ErrNum) & vbCrLf & _

            "Desc: " & ErrText

        GetFileDateTimeAsFILETIME = C_ERROR

        Exit Function

    End If

    Select Case WhichDateToGet

        Case FileDateCreate

            '''''''''''''''''''''''''''''''''''''''''''''''''''

            ' Call the GetFileTimeCreate flavor of GetFileTime.

            '''''''''''''''''''''''''''''''''''''''''''''''''''

            Res = GetFileTimeCreate( _

                hFile:=FileHandle, _

                CreateTime:=tFileTime, _

                LastAccessTime:=NULL_LONG, _

                LastModified:=NULL_LONG)

            If Res = 0 Then

                ErrNum = Err.LastDllError

                ErrText = GetSystemErrorMessageText(ErrNum)

                Debug.Print "Error With GetFileTimeAsFILETIME:" & vbCrLf & _

                            "Err:  " & CStr(ErrNum) & vbCrLf & _

                            "Desc: " & ErrText

                GetFileDateTimeAsFILETIME = C_ERROR

                Exit Function

            End If

        Case FileDateLastAccess

            '''''''''''''''''''''''''''''''''''''''''''''''''''

            ' Call the GetFileTimeLastAccess flavor of GetFileTime.

            '''''''''''''''''''''''''''''''''''''''''''''''''''

            Res = GetFileTimeLastAccess( _

                hFile:=FileHandle, _

                CreateTime:=NULL_LONG, _

                LastAccessTime:=tFileTime, _

                LastModified:=NULL_LONG)

            If Res = 0 Then

                ErrNum = Err.LastDllError

                ErrText = GetSystemErrorMessageText(ErrNum)

                Debug.Print "Error With GetFileTimeAsFILETIME:" & vbCrLf & _

                            "Err:  " & CStr(ErrNum) & vbCrLf & _

                            "Desc: " & ErrText

                GetFileDateTimeAsFILETIME = C_ERROR

                Exit Function

            End If

        Case FileDateLastModified

            '''''''''''''''''''''''''''''''''''''''''''''''''''

            ' Call the GetFileTimeLastModified flavor of GetFileTime.

            '''''''''''''''''''''''''''''''''''''''''''''''''''

            Res = GetFileTimeLastModified( _

                hFile:=FileHandle, _

                CreateTime:=NULL_LONG, _

                LastAccessTime:=NULL_LONG, _

                LastModified:=tFileTime)

            If Res = 0 Then

                ErrNum = Err.LastDllError

                ErrText = GetSystemErrorMessageText(ErrNum)

                Debug.Print "Error With GetFileTimeAsFILETIME:" & vbCrLf & _

                            "Err:  " & CStr(ErrNum) & vbCrLf & _

                            "Desc: " & ErrText

                GetFileDateTimeAsFILETIME = C_ERROR

                Exit Function

            End If

        Case Else

            ''''''''''''''''''''''''''''''''''''''

            ' Invalid value for WhichDateToChange.

            ''''''''''''''''''''''''''''''''''''''

            Debug.Print "Invalid value for WhichDateToChange: " & CStr(WhichDateToGet)

            CloseHandle FileHandle

            GetFileDateTimeAsFILETIME = C_ERROR

            Exit Function

    End Select

    If ConvertFromGMT = False Then

        '''''''''''''''''''''''''''''''''''''''''''''''

        ' ConvertFromGMT is False, so we don't do any

        ' conversion from GMT. The value placed in FTime

        ' is a GMT value. Set the elements of the FTime

        ' variable that was passed in to this function.

        '''''''''''''''''''''''''''''''''''''''''''''''

        FTime.dwHighDateTime = tFileTime.dwHighDateTime

        FTime.dwLowDateTime = tFileTime.dwLowDateTime

    Else

        '''''''''''''''''''''''''''''''''''''''''''''''

        ' ConvertFromGMT is True, so we must convert

        ' fFileTime from GMT to a local time value.

        ' Convert to local time and then set the elements

        ' of the FTime variable that was passed into

        ' this procedure.

        '''''''''''''''''''''''''''''''''''''''''''''''

        Res = FileTimeToLocalFileTime(lpFileTime:=tFileTime, lpLocalFileTime:=tLocalFileTime)

        If Res = 0 Then

            ErrNum = Err.LastDllError

            ErrText = GetSystemErrorMessageText(ErrNum)

            Debug.Print "Error With FileTimeToLocalFileTime:" & vbCrLf & _

                        "Err:  " & CStr(ErrNum) & vbCrLf & _

                        "Desc: " & ErrText

            GetFileDateTimeAsFILETIME = C_ERROR

            Exit Function

        End If

        FTime.dwHighDateTime = tLocalFileTime.dwHighDateTime

        FTime.dwLowDateTime = tLocalFileTime.dwLowDateTime

    End If

    '''''''''''''''''''''''''''''''''''''

    ' If we made it this far, we're

    ' successful so return True.

    '''''''''''''''''''''''''''''''''''''

    GetFileDateTimeAsFILETIME = True

    End Function

    Sub revisedDateCreation()

    Dim FName As String

    Dim Result As Boolean

    Dim TheNewTime As Double

    Dim WhatTime As FileDateToProcess

    Dim TheNewDate As Double

    '''''''''''''''''''''''''''''''

    ' Craete the new date and time.

    '''''''''''''''''''''''''''''''

    TheNewDate = DateSerial(2015, 1, 1)              '<---customizza la data

    TheNewDate = TheNewDate + TimeSerial(11, 0, 0) '<---customizza l'ora

    FName = "pathCompletoDelFile" **** '<---customizza il nome del file

    Result = SetFileDateTime(FileName:=FName, FileDateTime:=TheNewDate, _

                             WhichDateToChange:=1, NoGMTConvert:=False)

    If Result = True Then

        Debug.Print "File date/time successfully modified."

    Else

        Debug.Print "An error occurred with SetFileDateTime."

    End If

    End Sub

    La risposta è stata utile?

    0 commenti Nessun commento
  5. Anonimo
    2015-12-04T17:52:45+00:00

    Ciao Fausto Leggio

    nonostante si possa pensare che la data di creazione del file sia non modificabile, in realtà così non è.

    Al seguente link trovi una spiegazione in merito:

    How can the Date Created be later than the date modified?

    Al seguente link trovi invece un interessante approfondimento  sul tema "date e filesystem":

    Dates: NTFS Created, Modified, Accessed, Written

    David

    La risposta è stata utile?

    0 commenti Nessun commento