Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I read a file's creation date?

Status
Not open for further replies.

yakiyak

IS-IT--Management
Jun 10, 2003
5
US
I'm using the NAME command in Access to move files from one directory to another and change the name. How do I tell it to include the file's creation date in the filename?
Example: I need "data.xls" to become "mmddyyy data.xls"

strFolder = "C:\my documents\"
strName = "data.xls"
strFile = strFolder & strName

Name strFile AS ???????
 
yakiyak,

Code:
Sub ShowFileInfo(filespec)
    Dim fs, f, s
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.GetFile(filespec)
    s = "Created: " & f.DateCreated
    MsgBox s
End Sub
Hope this helps :)

Skip,
Skip@TheOfficeExperts.com
 
Skip,
What is filespec and how do I pass the data.xls file the function? and how do I get the function to return the date when I call it? Is this how I would do it?

Call ShowFileInfo ("C:\data.xls")
Name strFile As s

Sub ShowFileInfo(filespec)As String
Dim fs, f, s
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(filespec)
s = "Created: " & f.DateCreated
Return s
End Sub

Thanks for the help
 
filespec is your path and filename.

This example could be turned into a function as follows...
Code:
Function CreateDate(filespec) As String
    Dim fs, f
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.GetFile(filespec)
    CreateDate = f.DateCreated
End Function
Hope this helps :)

Skip,
Skip@TheOfficeExperts.com
 
When I tried this code, I get a file not found error but the file is in the proper location (network drive). Does this code work for Windows 2000?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top