By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,824 Members | 2,359 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,824 IT Pros & Developers. It's quick & easy.

How to get the date text a file was created

100+
P: 365
Hello,

I want to read the attributes of a single text file (.txt), specifically the date/time created from within VB. i cant figure it out,

Any ideas?

Cheers
May 14 '10 #1

✓ answered by ADezii

@Dan2kx
Using the KISS principal:
Expand|Select|Wrap|Line Numbers
  1. Const conFILE_PATH As String = "C:\Windows\System\YaDa-YaDa.txt"
  2.  
  3. If Dir$(conFILE_PATH) <> "" Then
  4.   MsgBox conFILE_PATH & " Created: " & FileDateTime(conFILE_PATH)
  5. Else
  6.   MsgBox "[" & conFILE_PATH & "] does not exist in the specified Path", _
  7.           vbExclamation, "Nadda File"
  8. End If

Share this Question
Share on Google+
3 Replies


Jim Doherty
Expert 100+
P: 897
@Dan2kx
Here you go Dan:-

Just pass your full path and filename to the function

Expand|Select|Wrap|Line Numbers
  1. Function GetMyFileCreationDate(MyFilePath As String)
  2.     If MyFilePath = "" Then Exit Function
  3.     Dim myFS As Object
  4.     'Using Microsoft Scripting Runtime FileSystemObject
  5.     Set myFS = CreateObject("Scripting.FileSystemObject")
  6.     'Return the creation date to the calling procedure
  7.     If myFS.FileExists(MyFilePath) Then
  8.     GetMyFileCreationDate = myFS.GetFile(MyFilePath).DateCreated
  9.     Else
  10.     GetMyFileCreationDate = "File does not exist in the path"
  11.     End If
  12.     Set myFS = Nothing
  13. End Function
May 14 '10 #2

ADezii
Expert 5K+
P: 8,636
@Dan2kx
Using the KISS principal:
Expand|Select|Wrap|Line Numbers
  1. Const conFILE_PATH As String = "C:\Windows\System\YaDa-YaDa.txt"
  2.  
  3. If Dir$(conFILE_PATH) <> "" Then
  4.   MsgBox conFILE_PATH & " Created: " & FileDateTime(conFILE_PATH)
  5. Else
  6.   MsgBox "[" & conFILE_PATH & "] does not exist in the specified Path", _
  7.           vbExclamation, "Nadda File"
  8. End If
May 14 '10 #3

100+
P: 365
I forgot to thank you guys, so... erm... thanks

I used Adezii's method because it was less code, i like that...

Cheers
May 17 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.