- '*****Dans une form*****
- Dim Fichier_Path As String: Fichier_Path = ""
- Dim Fichier_Existe As Boolean: Fichier_Existe = False
- Dim Fichier_Date As String: Fichier_Date = ""
-
- '**Fichier cible : test.txt**
- If Right(App.Path, 1) <> "\" Then
- Fichier_Path = App.Path & "\" & "test.txt"
- Else
- Fichier_Path = App.Path & "test.txt"
- End If
- Call Date_File(Fichier_Path, Fichier_Existe, Fichier_Date)
-
-
- '*****On peut mettre le reste dans un module*****
-
- Private Declare Function FileTimeToLocalFileTime Lib "kernel32" (lpFileTime As FILETIME, lpLocalFileTime As FILETIME) As Long
- Private Declare Function FileTimeToSystemTime Lib "kernel32" (lpFileTime As FILETIME, lpSystemTime As SYSTEMTIME) As Long
- Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
- Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
-
- Private Const MAX_PATH = 260
-
- Private Type FILETIME
- dwLowDateTime As Long
- dwHighDateTime As Long
- End Type
-
- Private Type WIN32_FIND_DATA
- dwFileAttributes As Long
- ftCreationTime As FILETIME
- ftLastAccessTime As FILETIME
- ftLastWriteTime As FILETIME
- nFileSizeHigh As Long
- nFileSizeLow As Long
- dwReserved0 As Long
- dwReserved1 As Long
- cFileName As String * MAX_PATH
- cAlternate As String * 14
- End Type
-
- Private 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 Sub Date_File(Chemin_File As String, Existe_File As Boolean, Date_File As String)
-
- If Dir(Chemin_File, vbNormal) = "" Then 'Le fichier n'existe pas
- Existe_File = False
- Exit Sub
- Else 'Le fichier existe
- Existe_File = True
- End If
-
- Dim Info_Fichier As WIN32_FIND_DATA
- '**Localise/identifie le fichier sur le disque et Info_Fichier reçoit les informations**
- Call FindClose(FindFirstFile(UCase(Chemin_File), Info_Fichier))
-
- Dim ft As FILETIME
- '**Convertion de la date UTC en temps locale**
- Call FileTimeToLocalFileTime(Info_Fichier.ftCreationTime, ft)
-
- Dim st As SYSTEMTIME
- '**Convertion en date et heure system**
- Call FileTimeToSystemTime(ft, st)
-
- '**Date_File récupére la date sous forme : "11/11/2004"**
- Date_File = st.wDay & "/" & st.wMonth & "/" & st.wYear
-
- '**Autre exemple date et heure sous la forme "jeudi 11 novembre 2004 14:11:23"**
- Dim FileTimeToDouble As Double
- Dim FormatFileDate As String
- 'Renvoie la date correspondant au jour, au mois, à l'année indiqués etc...
- FileTimeToDouble = DateSerial(st.wYear, st.wMonth, st.wDay) + TimeSerial(st.wHour, st.wMinute, st.wSecond)
-
- 'Format la date de type sous forme : "jeudi 11 novembre 2004 14:11:23"
- FormatFileDate = Format(FileTimeToDouble, "long date") & " " & Format(FileTimeToDouble, "long time")
-
- End Sub
'*****Dans une form*****
Dim Fichier_Path As String: Fichier_Path = ""
Dim Fichier_Existe As Boolean: Fichier_Existe = False
Dim Fichier_Date As String: Fichier_Date = ""
'**Fichier cible : test.txt**
If Right(App.Path, 1) <> "\" Then
Fichier_Path = App.Path & "\" & "test.txt"
Else
Fichier_Path = App.Path & "test.txt"
End If
Call Date_File(Fichier_Path, Fichier_Existe, Fichier_Date)
'*****On peut mettre le reste dans un module*****
Private Declare Function FileTimeToLocalFileTime Lib "kernel32" (lpFileTime As FILETIME, lpLocalFileTime As FILETIME) As Long
Private Declare Function FileTimeToSystemTime Lib "kernel32" (lpFileTime As FILETIME, lpSystemTime As SYSTEMTIME) As Long
Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
Private Const MAX_PATH = 260
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * MAX_PATH
cAlternate As String * 14
End Type
Private 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 Sub Date_File(Chemin_File As String, Existe_File As Boolean, Date_File As String)
If Dir(Chemin_File, vbNormal) = "" Then 'Le fichier n'existe pas
Existe_File = False
Exit Sub
Else 'Le fichier existe
Existe_File = True
End If
Dim Info_Fichier As WIN32_FIND_DATA
'**Localise/identifie le fichier sur le disque et Info_Fichier reçoit les informations**
Call FindClose(FindFirstFile(UCase(Chemin_File), Info_Fichier))
Dim ft As FILETIME
'**Convertion de la date UTC en temps locale**
Call FileTimeToLocalFileTime(Info_Fichier.ftCreationTime, ft)
Dim st As SYSTEMTIME
'**Convertion en date et heure system**
Call FileTimeToSystemTime(ft, st)
'**Date_File récupére la date sous forme : "11/11/2004"**
Date_File = st.wDay & "/" & st.wMonth & "/" & st.wYear
'**Autre exemple date et heure sous la forme "jeudi 11 novembre 2004 14:11:23"**
Dim FileTimeToDouble As Double
Dim FormatFileDate As String
'Renvoie la date correspondant au jour, au mois, à l'année indiqués etc...
FileTimeToDouble = DateSerial(st.wYear, st.wMonth, st.wDay) + TimeSerial(st.wHour, st.wMinute, st.wSecond)
'Format la date de type sous forme : "jeudi 11 novembre 2004 14:11:23"
FormatFileDate = Format(FileTimeToDouble, "long date") & " " & Format(FileTimeToDouble, "long time")
End Sub