Ver Mensaje Individual
  #5 (permalink)  
Antiguo 16/03/2007, 02:18
Avatar de seba123neo
seba123neo
 
Fecha de Ingreso: febrero-2007
Ubicación: Esperanza, Santa Fe
Mensajes: 1.046
Antigüedad: 17 años, 2 meses
Puntos: 19
Re: Como puedo obtener la fecha de creación de un archivo ?

aca te dejo un ejemplo que funciona perfecto:pone 4 textbox,el primero va a ser para ingresar la ruta del archivo y su extencion.y los otros te muestran cuando fue creado modificado y ultimo ingreso.y tambien pone 3 botones,uno para salir y uno para apretarlo despues de ingresar la ruta que hace que te muestre los datos,y el otro para la ventana de propiedades del archivo.

Option Explicit

Private Const OFS_MAXPATHNAME = 128
Private Const OF_READWRITE = &H2

Private Type OFSTRUCT
cBytes As Byte
fFixedDisk As Byte
nErrCode As Integer
Reserved1 As Integer
Reserved2 As Integer
szPathName(0 to OFS_MAXPATHNAME -1) As Byte '0-based
End Type

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

Private Type TIME_ZONE_INFORMATION
Bias As Long
StandardName(0 to 31) As Integer '32, 0-based
StandardDate As SYSTEMTIME
StandardBias As Long
DaylightName(0 to 31) As Integer '32, 0-based
DaylightDate As SYSTEMTIME
DaylightBias As Long
End Type

Private Declare Sub GetLocalTime Lib "kernel32" _
(lpSystemTime As SYSTEMTIME)

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 FILETIME, _
lpLastAccessTime As FILETIME, _
lpLastWriteTime As FILETIME) As Long

Private Declare Function FileTimeToSystemTime Lib "kernel32" _
(lpFileTime As FILETIME, _
lpSystemTime As SYSTEMTIME) As Long

Private Declare Function SystemTimeToFileTime Lib "kernel32" _
(lpSystemTime As SYSTEMTIME, _
lpFileTime As FILETIME) As Long

Private Declare Function OpenFile Lib "kernel32" _
(ByVal lpFileName As String, _
lpReOpenBuff As OFSTRUCT, _
ByVal wStyle As Long) As Long

Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hFile As Long) As Long

Private Type SHELLEXECUTEINFO
cbSize As Long
fMask As Long
hwnd As Long
lpVerb As String
lpFile As String
lpParameters As String
lpDirectory As String
nShow As Long
hInstApp As Long
lpIDList As Long
lpClass As String
hkeyClass As Long
dwHotKey As Long
hIcon As Long
hProcess As Long
End Type

Private Const SEE_MASK_INVOKEIDLIST = &HC
Private Const SEE_MASK_NOCLOSEPROCESS = &H40
Private Const SEE_MASK_FLAG_NO_UI = &H400

Private Declare Function ShellExecuteEx Lib "shell32" _
Alias "ShellExecuteEx" _
(SEI As SHELLEXECUTEINFO) As Long



Private Sub Command1_Click()

Unload Me

End Sub


Private Sub Command2_Click()

'variables required
Dim hFile As Long
Dim fName As String
Dim tmp As String

'structures required
Dim OFS As OFSTRUCT
Dim SYS_TIME As SYSTEMTIME
Dim FT_CREATE As FILETIME
Dim FT_ACCESS As FILETIME
Dim FT_WRITE As FILETIME
Dim NEW_TIME As FILETIME

'assign the textbox entry to the filename
fName = (Text1)

'open the file
hFile = OpenFile(fName, OFS, OF_READWRITE)

'get the FILETIME info for the created,
'accessed and last write info
Call GetFileTime(hFile, FT_CREATE, FT_ACCESS, FT_WRITE)

'----- debug only ---------------------------
'show the system time info
tmp = "Date Created:" & vbTab & GetFileDateString(FT_CREATE) & vbCrLf
tmp = tmp & "Last Access:" & vbTab & GetFileDateString(FT_ACCESS) & vbCrLf
tmp = tmp & "Last Modified:" & vbTab & GetFileDateString(FT_WRITE)
Text2.Text = tmp
'--------------------------------------------

'obtain the local system time
'(adjusts for the GMT deviation
'of the local time zone)
GetLocalTime SYS_TIME

'----- debug only ---------------------------
'show the system time info
tmp = ""
tmp = "Day:" & vbTab & SYS_TIME.wDay & vbCrLf
tmp = tmp & "Month:" & vbTab & SYS_TIME.wMonth & vbCrLf
tmp = tmp & "Year:" & vbTab & SYS_TIME.wYear & vbCrLf
tmp = tmp & "String:" & vbTab & GetSystemDateString(SYS_TIME)
Text3.Text = tmp
'--------------------------------------------

'convert the system time to a valid file time
Call SystemTimeToFileTime(SYS_TIME, NEW_TIME)


'set the created, accessed and modified dates all
'to the new dates. A null (0&) could be passed as
'any of the NEW_TIME parameters to leave that date unchanged.
Call SetFileTime(hFile, NEW_TIME, NEW_TIME, NEW_TIME)

're-read the updated FILETIME info for the created,
'accessed and last write info
Call GetFileTime(hFile, FT_CREATE, FT_ACCESS, FT_WRITE)

'----- debug only ---------------------------
'show the system time info
tmp = "New Date Created:" & vbTab & GetFileDateString(FT_CREATE) & vbCrLf
tmp = tmp & "New Last Access:" & vbTab & GetFileDateString(FT_ACCESS) & vbCrLf
tmp = tmp & "New Last Modified:" & vbTab & GetFileDateString(FT_WRITE)
Text4.Text = tmp
'--------------------------------------------

'clean up by closing the file
Call CloseHandle(hFile)

End Sub


Private Sub Command3_Click()

Dim SEI As SHELLEXECUTEINFO

'Fill in the SHELLEXECUTEINFO structure
'and call the ShellExecuteEx API
With SEI
.cbSize = Len(SEI)
.fMask = SEE_MASK_NOCLOSEPROCESS Or _
SEE_MASK_INVOKEIDLIST Or _
SEE_MASK_FLAG_NO_UI
.hwnd = Me.hwnd
.lpVerb = "properties"
.lpFile = (Text1)
.lpParameters = vbNullChar
.lpDirectory = vbNullChar
.nShow = 0
.hInstApp = 0
.lpIDList = 0
End With

'call the API
Call ShellExecuteEx(SEI)

End Sub


Private Function GetFileDateString(CT As FILETIME) As String

Dim ST As SYSTEMTIME
Dim ds As Single

'convert the passed FILETIME to a
'valid SYSTEMTIME format for display
If FileTimeToSystemTime(CT, ST) Then
ds = DateSerial(ST.wYear, ST.wMonth, ST.wDay)
GetFileDateString = Format$(ds, "DDDD MMMM D, YYYY")
Else
GetFileDateString = ""
End If

End Function


Private Function GetSystemDateString(ST As SYSTEMTIME) As String

Dim ds As Single

ds = DateSerial(ST.wYear, ST.wMonth, ST.wDay)

If ds Then
GetSystemDateString = Format$(ds, "DDDD MMMM D, YYYY")
Else
GetSystemDateString = "error!"
End If

End Function

al correr el programa ingresa en el text1 la ruta del archivo y su extencion tambien y apreta el boton 2.