[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 14607
  • Last Modified:

Get File's date/timestamp with VB6

Hi,
I want to know how to use VB6 to get a file's date/timestamp.  When an application opens, I want to check to see if I can delete a backup file (should occur 90 days after last use).  Probably something straightforward, but I can't think of it right now.

Thanks.

Ken
0
kenspencer
Asked:
kenspencer
1 Solution
 
vinnyd79Commented:
Private Sub Form_Load()
If DateDiff("d", FileDateTime("C:\Somefile.txt"), Now) > 90 Then
    MsgBox "File is older than 90 days"
End If
End Sub
0
 
iHadiCommented:
Hi
This function will get the dateTime Stamp of a file and will automaticly return how many days old is the file

Private Function GetDiffDays(sFile As String)
Dim fDate As Date
Dim tmpNum As Long

fDate = FileDateTime(sFile)
tmpNum = DateDiff("d", fDate, Date)
GetDiffDays = tmpNum
End Function
0
 
JesterTooCommented:
This code fragment compares current date/time to the file's "last access date" instead of its "last updated date".  Uncomment the "kill" command to make it fully functional after testing.


'Add a reference to the Microsoft Scripting Runtime

'Private Sub Form_Load()
Sub Main()
Dim sFileName  As String

   sFileName = "C:\SomeFile.bak"

   If DateDiff("d", GetLastAccess(sFileName), Now) > 90 Then
       MsgBox "File is older than 90 days"
''       Kill (sFileName)
   End If

End Sub


Function GetLastAccess(sFile As String)
Dim oFSO   As Object
Dim oFile  As File
Dim sMsg   As String

    'Instantiate the FSO and get the oFile
    Set oFSO = CreateObject("Scripting.FileSystemObject")  
    Set oFile = oFSO.GetFile(sFile)

    GetLastAccess = oFile.DateLastAccessed

    'Clean up
    Set oFile = Nothing
    Set oFSO = Nothing
End Function


HTH,
Lynn
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
JesterTooCommented:
Note: I actually used the project reference for "Windows Script Host Object Model" instead of " Microsoft Scripting Runtime".
0
 
kenspencerAuthor Commented:
Everyone,
Thanks for the help.  I will check it out either late today or tomorrow.

Ken
0
 
kenspencerAuthor Commented:
Thanks for everyone's assistance.  The first answer was what I needed.

Ken
0
 
JesterTooCommented:
Ken, are you aware that  FileDateTime() returns the  LAST MODIFIED date/time?  That's not the same as "LAST USED" (unless every usage is also an update) which is what the script I posted uses.

-- Lynn
0
 
kenspencerAuthor Commented:
Lynn,
Backup file will be an Access database with 'Compact on Close' option turned on.  I may not have worded the question accurately, so your point is well taken.

Ken
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now