Comparing 2 files on date/time stamp, and based time difference do a subroutine

Comparing 2 files on date/time stamp, and based time difference do a subroutine

Post by info » Sat, 29 Sep 2007 10:17:00



Hello all,

I'm looking for a code which compares two given files. If the time
between the 2 files differ more than 10 minutes, a choise is given to
either open one file or the other.

such as:
N:\Shoes\Shoes.xls 2/14/2007 14:17
C:\Local\Shoes.xls 2/14/2007 16:22



It would be great if you could help me out here.
The code is needed in Excel-VBA 2002 SP2

Thanks! :-)
 
 
 

Comparing 2 files on date/time stamp, and based time difference do a subroutine

Post by Robin Hamm » Sat, 29 Sep 2007 11:53:27

This should get you started. It shows how to get the file time using the
windows scripting file system object.

Option Explicit

Sub Main()
EnumerateFileTimes ("C:\")
End Sub

Public Sub EnumerateFileTimes(strFolderPath As String)
Dim fsO As Object
Dim fsFolder As Object
Dim fsSubFolders As Object
Dim fsSub As Object
Dim fsFiles As Object
Dim fsFile As Object

Set fsO = CreateObject("Scripting.FileSystemObject")
Set fsFolder = fsO.GetFolder(strFolderPath)
Set fsSubFolders = fsFolder.Subfolders

For Each fsSub In fsSubFolders

Set fsFiles = fsSub.Files

For Each fsFile In fsFiles

Debug.Print "Folder: " & fsSub.Name, _
"File: " & fsFile.Name, _
"Date: " & FormatDateTime(fsFile.DateLastModified, vbShortDate),
_
"Time: " & FormatDateTime(fsFile.DateLastModified, vbShortTime)

Next

Next

End Sub


--
Robin Hammond
www.enhanceddatasystems.com