|
-
Oct 10th, 2000, 03:05 PM
#1
Thread Starter
Junior Member
Hello,
Does anyone know how to get file creation date/time using API?
Thank you very much!
-
Oct 10th, 2000, 03:12 PM
#2
Take a look at this thread .
-
Oct 10th, 2000, 05:41 PM
#3
_______
<?>
Code:
'an example of using API to get file information
'creation date and creation time
'or a file
Option Explicit
Private Const OF_READ = &H0
Private Const OF_WRITE = &H1
Private Const OF_READWRITE = &H2
Private Const OF_SHARE_COMPAT = &H0
Private Const OF_SHARE_EXCLUSIVE = &H10
Private Const OF_SHARE_DENY_WRITE = &H20
Private Const OF_SHARE_DENY_READ = &H30
Private Const OF_SHARE_DENY_NONE = &H40
Private Const OF_PARSE = &H100
Private Const OF_DELETE = &H200
Private Const OF_VERIFY = &H400
Private Const OF_CANCEL = &H800
Private Const OF_CREATE = &H1000
Private Const OF_PROMPT = &H2000
Private Const OF_EXIST = &H4000
Private Const OF_REOPEN = &H8000
Private Const OFS_MAXPATHNAME = 128
' OpenFile() Structure
Private Type OfStructureure
cBytes As Byte
fFixedDisk As Byte
nErrCode As Integer
Reserved1 As Integer
Reserved2 As Integer
szPathName(OFS_MAXPATHNAME) As Byte
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 Declare Function FileTimeToLocalFileTime Lib "kernel32.dll" (lpFileTime As FILETIME, lpLocalFileTime As FILETIME) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function GetFileTime 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 OpenFile Lib "kernel32" (ByVal lpFileName As String, lpReOpenBuff As OfStructureure, ByVal wStyle As Long) As Long
Private Declare Function SystemTimeToFileTime Lib "kernel32" (lpSystemTime As SYSTEMTIME, lpFileTime As FILETIME) As Long
Private Sub Command1_Click()
Dim hFile As Long, OFS As OfStructureure, _
l As Long, cTime As FILETIME, _
lTime As FILETIME, lwTime As FILETIME
Dim sTime As SYSTEMTIME, sMyString As String, _
MyFileTime As String, stFile As String, stDir As String
'my directory
stDir = "C:\Dirtbagdog\"
'my file within the directory
sMyString = Dir$(stDir & "*.*")
OFS.cBytes = Len(OFS)
Do While sMyString <> "" 'go through the folder (stdir)
sMyString = stDir & sMyString
'add the filename and path to listbox
List1.AddItem sMyString
'handle of file
hFile = OpenFile(sMyString, OFS, OF_WRITE)
'it the file exists then do your stuff
If hFile > 0 Then
l = GetFileTime(hFile, cTime, lTime, lwTime)
l = FileTimeToLocalFileTime(lwTime, lwTime)
l = FileTimeToSystemTime(lwTime, sTime)
MyFileTime = sTime.wHour & ":" & sTime.wMinute & ":" & sTime.wSecond
'add the time to a listbox
List1.AddItem MyFileTime
MyFileTime = sTime.wMonth & "/" & sTime.wDay & "/" & sTime.wYear
'add the date to a list box and a blank line
List1.AddItem MyFileTime
List1.AddItem "" 'space between file information
l = CloseHandle(hFile)
End If
sMyString = Dir
Loop
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Oct 11th, 2000, 08:03 AM
#4
Thread Starter
Junior Member
Re: <?>
Thanks!
You guys have never let me down! I can always count on someone responding!
Olga
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|