|
-
Sep 12th, 2000, 04:19 AM
#1
Thread Starter
Addicted Member
Hi all,
Could anyone help me out with the GETFILETIME API. I am trying to find the creation date of a load of files and struggling with getting the GETFILETIME API to work, anyone know how it works?
and could they explain what time zone the returned value would be in (I believe that all times are returned as GMT)
Cheers for any help
Steve
-
Sep 12th, 2000, 04:49 AM
#2
_______
<?>
[code]
'create a new app (standard)
'add a command button Command1 and
'add a listbox List1
'copy and past this code into the gen dec
'
'run the app.
'returns the system dates and times
Option Explicit
Private Sub Command1_Click()
'access all files within a folder
Dim stFile As String
Dim stDir As String
'your folder
stDir = "C:\My Documents\"
'each file
stFile = Dir$(stDir & "*.*")
'use file system object
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Do While stFile <> ""
List1.AddItem "The file " & stDir & stFile & " was created on: " & fso.GetFile(stDir & stFile).DateCreated
List1.AddItem "Last modification to file: " & fso.GetFile(stDir & stFile).DateLastModified
List1.AddItem "Last date file was accessed: " & fso.GetFile(stDir & stFile).DateLastAccessed
List1.AddItem ""
'next file in folder
stFile = Dir
Loop
End Sub
[code]
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Sep 12th, 2000, 07:30 AM
#3
Thread Starter
Addicted Member
Thanks
Thanks, I'll try it out
Is there a reason that you used the FSO rather than the API
Steve
-
Sep 12th, 2000, 07:52 AM
#4
Thread Starter
Addicted Member
It doesn't work
Just tried it out and it doesn't work, the following error occurs
Run-time error '429'
ActiveX component can't create object
Have you any idea how to solve this......??
Cheers for any help
Steve
-
Sep 12th, 2000, 08:00 AM
#5
_______
<?>
not particularly .. I just used it and continue to use it
I tested the code before pasting it...test it again.
Works fine.
What version of Vb are you using? And did you cut and paste the code.
Seems like you can't refernce fso perhaps an error in typing
the dim or set line or an older version of VB.
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Sep 12th, 2000, 08:17 AM
#6
Thread Starter
Addicted Member
Its VBA (Excel)
Maybe I need to add a reference.. perhaps !!!
Normally the CreateObject is used with Active X controls, Is the FSO an actual ActiveX control.. just guessing as maybe if this is the case I need to make a reference to it....
Again, Perhaps !!!
-
Sep 12th, 2000, 08:19 AM
#7
_______
<?>
yes, in VB the
'use file system object
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
createt the reference
looked up the api..it's a lot of a lot and it seems the
file has to be open to get the information.
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Sep 12th, 2000, 09:05 AM
#8
Thread Starter
Addicted Member
The API is strong with you young Programmer
On the same subject but not FSO, here is the API functions and code that I am using
Declare Function GetFileTime Lib "kernel32.dll" (ByVal hFile As Long, lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As FILETIME) As Long
Declare Function CreateFile Lib "kernel32.dll" 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
Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long
Declare Function FileTimeToSystemTime Lib "kernel32.dll" (lpFileTime As FILETIME, lpSystemTime As SYSTEMTIME)
Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
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_READ = &H1
Const FILE_SHARE_WRITE = &H2
Const CREATE_ALWAYS = 2
Const CREATE_NEW = 1
Const OPEN_ALWAYS = 4
Const OPEN_EXISTING = 3
Const TRUNCATE_EXISTING = 5
Const FILE_ATTRIBUTE_ARCHIVE = &H20
Const FILE_ATTRIBUTE_HIDDEN = &H2
Const FILE_ATTRIBUTE_NORMAL = &H80
Const FILE_ATTRIBUTE_READONLY = &H1
Const FILE_ATTRIBUTE_SYSTEM = &H4
Const FILE_FLAG_DELETE_ON_CLOSE = &H4000000
Const FILE_FLAG_NO_BUFFERING = &H20000000
Const FILE_FLAG_OVERLAPPED = &H40000000
Const FILE_FLAG_POSIX_SEMANTICS = &H1000000
Const FILE_FLAG_RANDOM_ACCESS = &H10000000
Const FILE_FLAG_SEQUENTIAL_SCAN = &H8000000
Const FILE_FLAG_WRITE_THROUGH = &H80000000
Private Sub GetmyDateValue()
Dim hFile As Long ' handle to the opened file
Dim ctime As FILETIME ' receives time of creation
Dim atime As FILETIME ' receives time of last access
Dim mtime As FILETIME ' receives time of last modification
Dim Thetime As SYSTEMTIME ' used to manipulate the time
Dim retval As Long ' return value
Dim Astr as string 'String value to hold date
hFile = CreateFile("My file name.whatever", GENERIC_READ, FILE_SHARE_READ, ByVal CLng(0), OPEN_EXISTING, FILE_ATTRIBUTE_ARCHIVE, 0)
retval = GetFileTime(hFile, ctime, atime, mtime)
retval = FileTimeToSystemTime(ctime, Thetime)
retval = CloseHandle(hFile)
Astr = Thetime.wMonth & "-" & Thetime.wDay & "-" & Thetime.wYear
msgbox Astr
End Sub
But I am receiving the following error
Run-time error '49'
Bad DLL calling convention
on the line calling FileTimeToSystemTime
Any Guru's got any ideas on the error or how to change the code....
Thanks for any help
steve
-
Sep 12th, 2000, 10:22 AM
#9
Thread Starter
Addicted Member
Ok Problem solved
I figured out why it wasn't working...
I didn't include the AS LONG at the end of the FileTimeTo SystemTime Function
Regards to all,
Steve
(Just in case anybody else ever has this problem !!)
-
Sep 12th, 2000, 10:33 AM
#10
_______
<?>
'an example of using API to get file information
'creation date and creation time
'or a file
Code:
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
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
|