?
Solved

How to get the dates of a folder?

Posted on 1998-12-16
6
Medium Priority
?
605 Views
Last Modified: 2012-08-13
I'm using the following code to get the dates
from files, but it does not work on folders...
(I get the "Could not open file!" MsgBox,
so the problem must be with the OpenFile...)
What is wrong?

Code:

Const OFS_MAXPATHNAME As Integer = 128

Declare Function OpenFile& Lib "kernel32" (ByVal lpFileName As String, lpReOpenBuff As OFSTRUCT, ByVal wStyle As Long)
Declare Function GetFileTime Lib "kernel32" (ByVal hFile As Long, lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As FILETIME) As Long

Public Type FILETIME
  dwLowDateTime As Long
  dwHighDateTime As Long
End Type

Public Type OFSTRUCT
  cBytes As Byte
  fFixedDisk As Byte
  nErrCode As Integer
  Reserved1 As Integer
  Reserved2 As Integer
  szPathName As String * OFS_MAXPATHNAME
End Type


Private Sub MySub()
  Dim hFile As Long
  Dim tCreateTime As FILETIME
  Dim tAccessTime As FILETIME
  Dim tWriteTime As FILETIME

  hFile = OpenFile("C:\Windows", 0)
  If hFile = -1 Then
      MsgBox "Could not open file!"
  End If

  If GetFileTime(hFile, tCreateTime, tAccessTime, tWriteTime) = 0 Then
    Call CloseHandle(hFile)
    MsgBox "Could not get file time!"
  End If

  Call CloseHandle(hFile)
End Sub
0
Comment
Question by:Olli083097
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 12

Expert Comment

by:mark2150
ID: 1450606
When I need something like this I use a "Q&D" (quick & dirty) method. I simply ask DOS for the info!

If you do:

SHELL( environ("comspec") & " /c dir \ /s /ad /-p /on > X", 1)

This will give you an ASCII text file containing all of the directories on the current disk into a little file called 'X'. It's simple enough to scan this file for the data you need.

While this is not particularly elegant, it does work very well even on networks. In my book a Q&D answer that is *right* and easy to code is worth more than an "elegant" answer that takes a week of programmer time to write & debug.

M

0
 
LVL 1

Expert Comment

by:muffinthedog
ID: 1450607
Or you could just use FindFirstFile and use the FILETIME returned in the ftCreationTime member of the WIN32_FIND_DATA structure. If you want an example...
0
 

Author Comment

by:Olli083097
ID: 1450608
mark2150: I don't want to do it the "Q&D" in this case...
muffinthedog: What is FindFirstFile???
If this can help me to find the Creation, Last Accessed and Changed time for folders. Then I guess I'm interested. So, how do I use it?

BTW: I'm not sure it is possible to get the Change time for folders... but if it is...
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Expert Comment

by:muffinthedog
ID: 1450609
Olli,
    LastAccess time and LastWrite time for a folder will return same as creation time... sorry

crummy little example though...

Dim FD As WIN32_FIND_DATA
Dim stCreationTime As SYSTEMTIME
Dim stLastAccessTime As SYSTEMTIME
Dim stLastWriteTime As SYSTEMTIME
FindFirstFile "C:\Download", FD
FileTimeToSystemTime FD.ftCreationTime, stCreationTime
FileTimeToSystemTime FD.ftLastAccessTime, stLastAccessTime
FileTimeToSystemTime FD.ftLastWriteTime, stLastWriteTime
MsgBox stCreationTime.wDay & "/" & stCreationTime.wMonth & "/" & stCreationTime.wYear
MsgBox stLastAccessTime.wDay & "/" & stLastAccessTime.wMonth & "/" & stLastAccessTime.wYear
MsgBox stLastWriteTime.wDay & "/" & stLastWriteTime.wMonth & "/" & stLastWriteTime.wYear

Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
Declare Function FileTimeToSystemTime Lib "kernel32" (lpFileTime As FILETIME, lpSystemTime As SYSTEMTIME) As Long

Public Const MAX_PATH = 260

Type FILETIME
        dwLowDateTime As Long
        dwHighDateTime As Long
End Type

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

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



0
 

Author Comment

by:Olli083097
ID: 1450610
muffinthedog:
Thanx!!! The code you gave me worked fine.

BTW: I don't know what it means, but I get dates on LastAccess and on LastWrite too. And they are different from creation time.

You can get the points if you answer the question!!!
0
 
LVL 1

Accepted Solution

by:
muffinthedog earned 200 total points
ID: 1450611
Olli,
    see comments. thanx...


0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question