Getting the date modified value of a file.


Hi there

I don't know whether Access will provide me with the solution.

Here's the problem ....

I need to develop a program that will check the date mofidfied of a file on the server and compare it to the one that is on my PC. The file names are the same. If the one on the server is more updated than the one on my PC then I have to copy the one on the server to my PC.

I know I have to extract the date modified values of both files and do the comparison.

How would I do something like this or would Visual Basic remedy the problem?

Thanks.
Leigh
LAPAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
BrianWrenConnect With a Mentor Commented:
Well, I was actually giving what is called a 'code snippet.'  The idea was to put it into a procedure, as follows.

On a form, put a command button, name it 'btnFileUpdate', and set its Click property to [Event Procedure].  Then click the elipsis to the right of the Click property, (the [...] button).

You will see

Private Sub btnFileUpdate()

End Sub

(You will need to change the file names I use below to reflect the true names and locations of your situation.)

Edit the sub so that it looks like:

Private Sub btnFileUpdate()

   On Error GoTo F_Ud_Err

   ' Next 2 lines is where you put your specific case.
   Const FileLoc = "C:\FileLoc\DataFile.txt"
   Const FileSvr = "\\Svr015\FileLoc\DataFile.txt"

   Dim fTimeLoc As Variant
   Dim fTimeSvr As Variant
   
   fTimeLoc = FileDateTime(FileLoc)
   fTimeSvr = FileDateTime(FileSvr)

   If fTimeSvr < fTimeLoc Then
      FileCopy FileLoc, FileSvr
      MsgBox "File was transferred"
   Else
      MsgBox "File was not transferred"
   End If

F_Ud_Res:
   Exit Sub

F_Ud_Err:
   MsgBox Err.Number & ", " & Err.Description
   Resume F_Ud_Res

End Sub

Save the form, run it, and when you click the button, the file dates and times will be retrieved, and if the server version is older, the server version will be replaced by the local version, and a message box will be displayed to let you know which action was taken.

If an error is encountered, you will be notified of that instead, and the sub will gracefully close.

That's a lot of answer for 27 points...  :o]

Brian
0
 
simonbennettCommented:
Leigh

You can do this in access code with the following API:

Type FILETIME
        dwLowDateTime As Long
        dwHighDateTime As Long
End Type

Declare Function GetFileTime Lib "kernel32" Alias "GetFileTime" (ByVal hFile As Long, lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As FILETIME) As Long

...or to be simpler, check out

http://support.microsoft.com/support/kb/articles/Q188/9/77.asp

HTH

Simon
0
 
LAPAuthor Commented:

Firstly, I don't have Visual FoxPro on my PC so I assume I can't make use of the code.

I've looked at the code at the site. It's seems quite complex and lengthy.

Doesn't MS Access have a simpler function!

Leigh
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
BrianWrenCommented:
--------------------------------------------------------------------------------------

Leigh,

   .
   .
   .

  Dim MyStamp As Variant

  ' Assume TESTFILE was last modified on Feb. 12, 1993 at 4:35:47 PM.
  ' Assume English/U.S. locale settings.
  MyStamp = FileDateTime("TESTFILE")      ' Returns "2/12/93 4:35:47 PM".


You can call this function to fill in one variant with one call, and a different variant with a second call, (using different strings for the argument to the FileDateTime function), then compare the results.

Brian
0
 
LAPAuthor Commented:

Brian,

when I compile that code I get the following error msg "Compile error: Invalid outside procedure"

How do I specify the path where the file can be found?

Leigh
0
 
LAPAuthor Commented:

Unable to make use of the example for  Visual FoxPro.

....sorry  :-(
0
 
LAPAuthor Commented:

Brian,

I am increasing the points to 100. :-)

I'll then accept your comment as the answer.

Thanks .... Leigh
0
 
LAPAuthor Commented:

Thanks!
0
All Courses

From novice to tech pro — start learning today.