Trouver la date fichier

Le
Michel69
Bonjour,

j'ai besoin d'obtenir la date de fichiers dans un répertoire du disque

Les instructions Dir() ou le CommonDialog ne rendent pas la date
apparemment

Avez vous une idée SVP ?

Merci à tous !!

Michel
Vidéos High-Tech et Jeu Vidéo
Téléchargements
Vos réponses
Gagnez chaque mois un abonnement Premium avec GNT : Inscrivez-vous !
Trier par : date / pertinence
Jean-marc
Le #15413151
Michel69 wrote:
Bonjour,

j'ai besoin d'obtenir la date de fichiers dans un répertoire du
disque...
Les instructions Dir(...) ou le CommonDialog ne rendent pas la date
apparemment...

Avez vous une idée SVP ?

Merci à tous !!



Hello Michel,

lors de notre dernière mise à jour de la FAQ du groupe,
nous avons justement amélioré l'article qui traite
du sujet. Voici le résultat :
http://faq.vb.free.fr/index.php?question6

Tu y trouveras la réponse à ta question ainsi que plein de
liens utiles (voir la section : "pour aller plus loin" à
la fin de l'article.

<pub>
La FAQ contient plein d'infos intéressantes :
http://faq.vb.free.fr/
</pub>

Bonne prog!

Cordialement,

--
Jean-marc Noury (jean_marc_n2)
Microsoft MVP - Visual Basic
mailto: remove '_no_spam_' ;
FAQ VB: http://faq.vb.free.fr/
Jacques93
Le #15413111
Bonjour Michel69,
Michel69 a écrit :
Bonjour,

j'ai besoin d'obtenir la date de fichiers dans un répertoire du disque...

Les instructions Dir(...) ou le CommonDialog ne rendent pas la date
apparemment...

Avez vous une idée SVP ?



Oui, la fonction FileDateTime,

Dim dt As Date
dt = FileDateTime("C:toto.txt")
MsgBox dt

renvoie la date de dernière modification du fichier.
Si tu as besoin des dates de création, et de dernier accès c'est un peu
plus complexe, via les API. Cela dépends d'une part du système de
fichier NTFS ou FAT32, qui les stocke de manières différentes : UTC
(Coordinate Universal Time) pour NTFS, ou Temps Local (prenant en compte
le fuseau horaire et heure d'été / heure d'hiver) pour FAT32. En plus
simple il y a FSO. Précise ton besoin si nécessaire.


Extrait d'une réponse que j'ai fait sur le forum Windows XP :

C'est conçu comme cela. En NTFS, les dates fichiers sont stockées sur 64
bits en nombre d'intervalles de 100 nanosecondes écoulées depuis le 1
janvier 1601 12:00 en Temps Universel UTC (Coordinated Universal Time).

Ce temps est récupéré par l'api 'GetFileDate', dans une structure FILETIME :

typedef struct _FILETIME {
DWORD dwLowDateTime;
DWORD dwHighDateTime;
} FILETIME, *PFILETIME;

qui est convertie en temps système par l'api 'FileTimeToSystemTime',
dans une structure SYSTEMTIME:

typedef struct _SYSTEMTIME {
WORD wYear;
WORD wMonth;
WORD wDayOfWeek;
WORD wDay;
WORD wHour;
WORD wMinute;
WORD wSecond;
WORD wMilliseconds;
} SYSTEMTIME, *PSYSTEMTIME;

qui est ajusté au temps local par l'api
'SystemTimeToTzSpecificLocalTime' à laquelle on transmet les
caractéristiques régionales dans une structure TIME_ZONE_INFORMATION :

typedef struct _TIME_ZONE_INFORMATION {
LONG Bias;
WCHAR StandardName[ 32 ];
SYSTEMTIME StandardDate;
LONG StandardBias;
WCHAR DaylightName[ 32 ];
SYSTEMTIME DaylightDate;
LONG DaylightBias;
} TIME_ZONE_INFORMATION, *PTIME_ZONE_INFORMATION;

elle même récupérée par l'api 'GetTimeZoneInformation'

Plus de détails ici (en anglais) :


NB : Il y a d'autres moyens d'y parvenir, mais le résultat est le même.

--
Cordialement,

Jacques.
LE TROLL
Le #15413091
Bonsoir,

Tiens j'ai ça, si c'est ce que tu évoque, mais ça fait un morceau:

'getion des 3 dates fichier
Option Explicit
'
' text1 + text2 + text3 + command1
'
Private Declare Function GetFileTime Lib "kernel32" (ByVal hFile As Long,
lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As
FILETIME) 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 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 LocalFileTimeToFileTime Lib "kernel32"
(lpLocalFileTime As FILETIME, lpFileTime As FILETIME) As Long
Private Declare Function SystemTimeToFileTime Lib "kernel32" (lpSystemTime
As SYSTEMTIME, lpFileTime As FILETIME) As Long
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 CloseHandle Lib "kernel32" (ByVal hObject As
Long) As Long
'
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
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
'
Const GENERIC_READ = &H80000000
Const GENERIC_WRITE = &H40000000
Const FILE_SHARE_WRITE = &H2
Const FILE_SHARE_READ = &H1
Const OPEN_EXISTING = 3
Const FILE_ATTRIBUTE_ARCHIVE = &H20
'
Dim NomFichier As String
Dim RetVal As Long
Dim hFile As Long
'
Dim AccessTime As FILETIME
Dim CreationTime As FILETIME
Dim LastWriteTime As FILETIME
Dim WriteTime As FILETIME
Dim SYSTEMTIME As SYSTEMTIME
Dim TimeSystem As SYSTEMTIME
'
Sub Form_Load() ' lecture
ChDrive App.Path
ChDir App.Path
Call lit_temps
End Sub

Sub lit_temps()
NomFichier = App.Path & "test.txt"
hFile = CreateFile(NomFichier, GENERIC_READ, FILE_SHARE_READ, ByVal
CLng(0), OPEN_EXISTING, FILE_ATTRIBUTE_ARCHIVE, 0)
If hFile = -1 Then
MsgBox "Impossible d'ouvrir le fichier : " + NomFichier, vbExclamation
Exit Sub
End If
'
RetVal = GetFileTime(hFile, CreationTime, AccessTime, LastWriteTime) '
date
RetVal = FileTimeToLocalFileTime(CreationTime, CreationTime) ' date locale
filetime
RetVal = FileTimeToLocalFileTime(AccessTime, AccessTime)
RetVal = FileTimeToLocalFileTime(LastWriteTime, LastWriteTime)
'
RetVal = FileTimeToSystemTime(CreationTime, SYSTEMTIME) ' date systemTime
Text1 = SYSTEMTIME.wDay & "/" & SYSTEMTIME.wMonth & "/" & SYSTEMTIME.wYear
& " " & SYSTEMTIME.wHour & ":" & SYSTEMTIME.wMinute & ":" &
SYSTEMTIME.wSecond
RetVal = FileTimeToSystemTime(AccessTime, SYSTEMTIME)
Text2 = SYSTEMTIME.wDay & "/" & SYSTEMTIME.wMonth & "/" & SYSTEMTIME.wYear
& " " & SYSTEMTIME.wHour & ":" & SYSTEMTIME.wMinute & ":" &
SYSTEMTIME.wSecond
RetVal = FileTimeToSystemTime(LastWriteTime, SYSTEMTIME)
Text3 = SYSTEMTIME.wDay & "/" & SYSTEMTIME.wMonth & "/" & SYSTEMTIME.wYear
& " " & SYSTEMTIME.wHour & ":" & SYSTEMTIME.wMinute & ":" &
SYSTEMTIME.wSecond
CloseHandle (hFile)
End Sub

Sub Command1_Click() ' change
hFile = CreateFile(NomFichier, GENERIC_WRITE, FILE_SHARE_WRITE Or
FILE_SHARE_READ, ByVal CLng(0), OPEN_EXISTING, 0, 0)
'
If hFile = -1 Then
MsgBox "Impossible d'ouvrir le fichier (fichier en lecture seule)" &
vbLf & NomFichier, vbExclamation
Exit Sub
End If
'
TimeSystem = ObtenirDateHeure(Text1)
RetVal = SystemTimeToFileTime(TimeSystem, CreationTime)
RetVal = LocalFileTimeToFileTime(CreationTime, CreationTime)
'
TimeSystem = ObtenirDateHeure(Text2)
RetVal = SystemTimeToFileTime(TimeSystem, AccessTime)
RetVal = LocalFileTimeToFileTime(AccessTime, AccessTime)
'
TimeSystem = ObtenirDateHeure(Text3)
RetVal = SystemTimeToFileTime(TimeSystem, WriteTime)
RetVal = LocalFileTimeToFileTime(WriteTime, WriteTime)
'
RetVal = SetFileTime(hFile, CreationTime, AccessTime, WriteTime) 'modif
file
CloseHandle (hFile)
End Sub

Private Function ObtenirDateHeure(Texte As String) As SYSTEMTIME
Dim nPosMois As Byte
Dim nPosAnnee As Byte
Dim nPosHeure As Byte
Dim nPosMinute As Byte
Dim nPosSeconde As Byte
'
nPosMois = InStr(Texte, "/")
nPosAnnee = InStr(nPosMois + 1, Texte, "/")
nPosHeure = InStr(Texte, " ")
nPosMinute = InStr(nPosHeure + 1, Texte, ":")
nPosSeconde = InStr(nPosMinute + 1, Texte, ":")
'
If nPosMois = 0 Or nPosAnnee = 0 Or nPosHeure = 0 Or nPosMinute = 0 Or
nPosSeconde = 0 Then
MsgBox "Entrez la date et l'heure au format : jj/mm/aaaa hh:mm:ss !",
vbExclamation
Exit Function
End If
'
ObtenirDateHeure.wDay = Val(Left$(Texte, nPosMois - 1))
ObtenirDateHeure.wMonth = Val(Mid$(Texte, nPosMois + 1, (nPosAnnee -
nPosMois)))
ObtenirDateHeure.wYear = Val(Mid$(Texte, nPosAnnee + 1, (nPosAnnee -
nPosMois + 2)))
ObtenirDateHeure.wHour = Val(Mid$(Texte, nPosHeure + 1, (nPosMinute -
nPosHeure)))
ObtenirDateHeure.wMinute = Val(Mid$(Texte, nPosMinute + 1, (nPosSeconde -
nPosMinute)))
ObtenirDateHeure.wSecond = Val(Mid$(Texte, nPosSeconde + 1))
End Function

Sub Form_Unload(Cancel As Integer)
CloseHandle (hFile)
End Sub

--
Romans, logiciels, email, site personnel
http://irolog.free.fr/joe.htm
------------------------------------------------------------------------------------
"Michel69" OrO%
Bonjour,

j'ai besoin d'obtenir la date de fichiers dans un répertoire du disque...

Les instructions Dir(...) ou le CommonDialog ne rendent pas la date
apparemment...

Avez vous une idée SVP ?

Merci à tous !!

Michel



Michel69
Le #15413061
Bonsoir à tous....

Et merci...

je vais utiliser la fonction FileDateTime qui semble bien répondre....

Cordialment... et MERCI

Michel


"Michel69" OrO%
Bonjour,

j'ai besoin d'obtenir la date de fichiers dans un répertoire du disque...

Les instructions Dir(...) ou le CommonDialog ne rendent pas la date
apparemment...

Avez vous une idée SVP ?

Merci à tous !!

Michel



Driss HANIB
Le #15412881
tiens tu utilises des API maintenant ?
;o))


"LE TROLL" news:
Bonsoir,

Tiens j'ai ça, si c'est ce que tu évoque, mais ça fait un morceau:

'getion des 3 dates fichier
Option Explicit
'
' text1 + text2 + text3 + command1
'
Private Declare Function GetFileTime Lib "kernel32" (ByVal hFile As


Long,
lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime


As
FILETIME) 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 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 LocalFileTimeToFileTime Lib "kernel32"
(lpLocalFileTime As FILETIME, lpFileTime As FILETIME) As Long
Private Declare Function SystemTimeToFileTime Lib "kernel32"


(lpSystemTime
As SYSTEMTIME, lpFileTime As FILETIME) As Long
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 CloseHandle Lib "kernel32" (ByVal hObject As
Long) As Long
'
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
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
'
Const GENERIC_READ = &H80000000
Const GENERIC_WRITE = &H40000000
Const FILE_SHARE_WRITE = &H2
Const FILE_SHARE_READ = &H1
Const OPEN_EXISTING = 3
Const FILE_ATTRIBUTE_ARCHIVE = &H20
'
Dim NomFichier As String
Dim RetVal As Long
Dim hFile As Long
'
Dim AccessTime As FILETIME
Dim CreationTime As FILETIME
Dim LastWriteTime As FILETIME
Dim WriteTime As FILETIME
Dim SYSTEMTIME As SYSTEMTIME
Dim TimeSystem As SYSTEMTIME
'
Sub Form_Load() ' lecture
ChDrive App.Path
ChDir App.Path
Call lit_temps
End Sub

Sub lit_temps()
NomFichier = App.Path & "test.txt"
hFile = CreateFile(NomFichier, GENERIC_READ, FILE_SHARE_READ, ByVal
CLng(0), OPEN_EXISTING, FILE_ATTRIBUTE_ARCHIVE, 0)
If hFile = -1 Then
MsgBox "Impossible d'ouvrir le fichier : " + NomFichier, vbExclamation
Exit Sub
End If
'
RetVal = GetFileTime(hFile, CreationTime, AccessTime, LastWriteTime) '
date
RetVal = FileTimeToLocalFileTime(CreationTime, CreationTime) ' date


locale
filetime
RetVal = FileTimeToLocalFileTime(AccessTime, AccessTime)
RetVal = FileTimeToLocalFileTime(LastWriteTime, LastWriteTime)
'
RetVal = FileTimeToSystemTime(CreationTime, SYSTEMTIME) ' date


systemTime
Text1 = SYSTEMTIME.wDay & "/" & SYSTEMTIME.wMonth & "/" &


SYSTEMTIME.wYear
& " " & SYSTEMTIME.wHour & ":" & SYSTEMTIME.wMinute & ":" &
SYSTEMTIME.wSecond
RetVal = FileTimeToSystemTime(AccessTime, SYSTEMTIME)
Text2 = SYSTEMTIME.wDay & "/" & SYSTEMTIME.wMonth & "/" &


SYSTEMTIME.wYear
& " " & SYSTEMTIME.wHour & ":" & SYSTEMTIME.wMinute & ":" &
SYSTEMTIME.wSecond
RetVal = FileTimeToSystemTime(LastWriteTime, SYSTEMTIME)
Text3 = SYSTEMTIME.wDay & "/" & SYSTEMTIME.wMonth & "/" &


SYSTEMTIME.wYear
& " " & SYSTEMTIME.wHour & ":" & SYSTEMTIME.wMinute & ":" &
SYSTEMTIME.wSecond
CloseHandle (hFile)
End Sub

Sub Command1_Click() ' change
hFile = CreateFile(NomFichier, GENERIC_WRITE, FILE_SHARE_WRITE Or
FILE_SHARE_READ, ByVal CLng(0), OPEN_EXISTING, 0, 0)
'
If hFile = -1 Then
MsgBox "Impossible d'ouvrir le fichier (fichier en lecture seule)" &
vbLf & NomFichier, vbExclamation
Exit Sub
End If
'
TimeSystem = ObtenirDateHeure(Text1)
RetVal = SystemTimeToFileTime(TimeSystem, CreationTime)
RetVal = LocalFileTimeToFileTime(CreationTime, CreationTime)
'
TimeSystem = ObtenirDateHeure(Text2)
RetVal = SystemTimeToFileTime(TimeSystem, AccessTime)
RetVal = LocalFileTimeToFileTime(AccessTime, AccessTime)
'
TimeSystem = ObtenirDateHeure(Text3)
RetVal = SystemTimeToFileTime(TimeSystem, WriteTime)
RetVal = LocalFileTimeToFileTime(WriteTime, WriteTime)
'
RetVal = SetFileTime(hFile, CreationTime, AccessTime, WriteTime)


'modif
file
CloseHandle (hFile)
End Sub

Private Function ObtenirDateHeure(Texte As String) As SYSTEMTIME
Dim nPosMois As Byte
Dim nPosAnnee As Byte
Dim nPosHeure As Byte
Dim nPosMinute As Byte
Dim nPosSeconde As Byte
'
nPosMois = InStr(Texte, "/")
nPosAnnee = InStr(nPosMois + 1, Texte, "/")
nPosHeure = InStr(Texte, " ")
nPosMinute = InStr(nPosHeure + 1, Texte, ":")
nPosSeconde = InStr(nPosMinute + 1, Texte, ":")
'
If nPosMois = 0 Or nPosAnnee = 0 Or nPosHeure = 0 Or nPosMinute = 0 Or
nPosSeconde = 0 Then
MsgBox "Entrez la date et l'heure au format : jj/mm/aaaa hh:mm:ss !",
vbExclamation
Exit Function
End If
'
ObtenirDateHeure.wDay = Val(Left$(Texte, nPosMois - 1))
ObtenirDateHeure.wMonth = Val(Mid$(Texte, nPosMois + 1, (nPosAnnee -
nPosMois)))
ObtenirDateHeure.wYear = Val(Mid$(Texte, nPosAnnee + 1, (nPosAnnee -
nPosMois + 2)))
ObtenirDateHeure.wHour = Val(Mid$(Texte, nPosHeure + 1, (nPosMinute -
nPosHeure)))
ObtenirDateHeure.wMinute = Val(Mid$(Texte, nPosMinute + 1,


(nPosSeconde -
nPosMinute)))
ObtenirDateHeure.wSecond = Val(Mid$(Texte, nPosSeconde + 1))
End Function

Sub Form_Unload(Cancel As Integer)
CloseHandle (hFile)
End Sub

--
Romans, logiciels, email, site personnel
http://irolog.free.fr/joe.htm
--------------------------------------------------------------------------


----------
"Michel69" OrO%
> Bonjour,
>
> j'ai besoin d'obtenir la date de fichiers dans un répertoire du


disque...
>
> Les instructions Dir(...) ou le CommonDialog ne rendent pas la date
> apparemment...
>
> Avez vous une idée SVP ?
>
> Merci à tous !!
>
> Michel
>




LE TROLL
Le #15412871
Quand on ne peut pas faire autrement en VB...

--
Merci beaucoup, au revoir et à bientôt :o)
------
Romans, logiciels, email, site personnel
http://irolog.free.fr/joe.htm
------------------------------------------------------------------------------------
"Driss HANIB"
tiens tu utilises des API maintenant ?
;o))


"LE TROLL" news:
Bonsoir,

Tiens j'ai ça, si c'est ce que tu évoque, mais ça fait un morceau:

'getion des 3 dates fichier
Option Explicit
'
' text1 + text2 + text3 + command1
'
Private Declare Function GetFileTime Lib "kernel32" (ByVal hFile As


Long,
lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime


As
FILETIME) 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 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 LocalFileTimeToFileTime Lib "kernel32"
(lpLocalFileTime As FILETIME, lpFileTime As FILETIME) As Long
Private Declare Function SystemTimeToFileTime Lib "kernel32"


(lpSystemTime
As SYSTEMTIME, lpFileTime As FILETIME) As Long
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 CloseHandle Lib "kernel32" (ByVal hObject As
Long) As Long
'
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
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
'
Const GENERIC_READ = &H80000000
Const GENERIC_WRITE = &H40000000
Const FILE_SHARE_WRITE = &H2
Const FILE_SHARE_READ = &H1
Const OPEN_EXISTING = 3
Const FILE_ATTRIBUTE_ARCHIVE = &H20
'
Dim NomFichier As String
Dim RetVal As Long
Dim hFile As Long
'
Dim AccessTime As FILETIME
Dim CreationTime As FILETIME
Dim LastWriteTime As FILETIME
Dim WriteTime As FILETIME
Dim SYSTEMTIME As SYSTEMTIME
Dim TimeSystem As SYSTEMTIME
'
Sub Form_Load() ' lecture
ChDrive App.Path
ChDir App.Path
Call lit_temps
End Sub

Sub lit_temps()
NomFichier = App.Path & "test.txt"
hFile = CreateFile(NomFichier, GENERIC_READ, FILE_SHARE_READ, ByVal
CLng(0), OPEN_EXISTING, FILE_ATTRIBUTE_ARCHIVE, 0)
If hFile = -1 Then
MsgBox "Impossible d'ouvrir le fichier : " + NomFichier,
vbExclamation
Exit Sub
End If
'
RetVal = GetFileTime(hFile, CreationTime, AccessTime, LastWriteTime) '
date
RetVal = FileTimeToLocalFileTime(CreationTime, CreationTime) ' date


locale
filetime
RetVal = FileTimeToLocalFileTime(AccessTime, AccessTime)
RetVal = FileTimeToLocalFileTime(LastWriteTime, LastWriteTime)
'
RetVal = FileTimeToSystemTime(CreationTime, SYSTEMTIME) ' date


systemTime
Text1 = SYSTEMTIME.wDay & "/" & SYSTEMTIME.wMonth & "/" &


SYSTEMTIME.wYear
& " " & SYSTEMTIME.wHour & ":" & SYSTEMTIME.wMinute & ":" &
SYSTEMTIME.wSecond
RetVal = FileTimeToSystemTime(AccessTime, SYSTEMTIME)
Text2 = SYSTEMTIME.wDay & "/" & SYSTEMTIME.wMonth & "/" &


SYSTEMTIME.wYear
& " " & SYSTEMTIME.wHour & ":" & SYSTEMTIME.wMinute & ":" &
SYSTEMTIME.wSecond
RetVal = FileTimeToSystemTime(LastWriteTime, SYSTEMTIME)
Text3 = SYSTEMTIME.wDay & "/" & SYSTEMTIME.wMonth & "/" &


SYSTEMTIME.wYear
& " " & SYSTEMTIME.wHour & ":" & SYSTEMTIME.wMinute & ":" &
SYSTEMTIME.wSecond
CloseHandle (hFile)
End Sub

Sub Command1_Click() ' change
hFile = CreateFile(NomFichier, GENERIC_WRITE, FILE_SHARE_WRITE Or
FILE_SHARE_READ, ByVal CLng(0), OPEN_EXISTING, 0, 0)
'
If hFile = -1 Then
MsgBox "Impossible d'ouvrir le fichier (fichier en lecture seule)"
&
vbLf & NomFichier, vbExclamation
Exit Sub
End If
'
TimeSystem = ObtenirDateHeure(Text1)
RetVal = SystemTimeToFileTime(TimeSystem, CreationTime)
RetVal = LocalFileTimeToFileTime(CreationTime, CreationTime)
'
TimeSystem = ObtenirDateHeure(Text2)
RetVal = SystemTimeToFileTime(TimeSystem, AccessTime)
RetVal = LocalFileTimeToFileTime(AccessTime, AccessTime)
'
TimeSystem = ObtenirDateHeure(Text3)
RetVal = SystemTimeToFileTime(TimeSystem, WriteTime)
RetVal = LocalFileTimeToFileTime(WriteTime, WriteTime)
'
RetVal = SetFileTime(hFile, CreationTime, AccessTime, WriteTime)


'modif
file
CloseHandle (hFile)
End Sub

Private Function ObtenirDateHeure(Texte As String) As SYSTEMTIME
Dim nPosMois As Byte
Dim nPosAnnee As Byte
Dim nPosHeure As Byte
Dim nPosMinute As Byte
Dim nPosSeconde As Byte
'
nPosMois = InStr(Texte, "/")
nPosAnnee = InStr(nPosMois + 1, Texte, "/")
nPosHeure = InStr(Texte, " ")
nPosMinute = InStr(nPosHeure + 1, Texte, ":")
nPosSeconde = InStr(nPosMinute + 1, Texte, ":")
'
If nPosMois = 0 Or nPosAnnee = 0 Or nPosHeure = 0 Or nPosMinute = 0 Or
nPosSeconde = 0 Then
MsgBox "Entrez la date et l'heure au format : jj/mm/aaaa hh:mm:ss
!",
vbExclamation
Exit Function
End If
'
ObtenirDateHeure.wDay = Val(Left$(Texte, nPosMois - 1))
ObtenirDateHeure.wMonth = Val(Mid$(Texte, nPosMois + 1, (nPosAnnee -
nPosMois)))
ObtenirDateHeure.wYear = Val(Mid$(Texte, nPosAnnee + 1, (nPosAnnee -
nPosMois + 2)))
ObtenirDateHeure.wHour = Val(Mid$(Texte, nPosHeure + 1, (nPosMinute -
nPosHeure)))
ObtenirDateHeure.wMinute = Val(Mid$(Texte, nPosMinute + 1,


(nPosSeconde -
nPosMinute)))
ObtenirDateHeure.wSecond = Val(Mid$(Texte, nPosSeconde + 1))
End Function

Sub Form_Unload(Cancel As Integer)
CloseHandle (hFile)
End Sub

--
Romans, logiciels, email, site personnel
http://irolog.free.fr/joe.htm
--------------------------------------------------------------------------


----------
"Michel69" OrO%
> Bonjour,
>
> j'ai besoin d'obtenir la date de fichiers dans un répertoire du


disque...
>
> Les instructions Dir(...) ou le CommonDialog ne rendent pas la date
> apparemment...
>
> Avez vous une idée SVP ?
>
> Merci à tous !!
>
> Michel
>








Publicité
Poster une réponse
Anonyme