×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Get modified date on files in folder

Get modified date on files in folder

Get modified date on files in folder

(OP)
Hi guys

I'm trying to return the latest modified date of the all files in a folder.

Have tried this code

Dim Dato As String
Dato = DLookup("Path", "tblSys", "")
Me.txtMod.Value = FileDateTime(left((Dato), Len(Dato) - 1))

this returns the modified path modified date but I'd like the neweste modification date of all the files

Any ideas ???

 

RE: Get modified date on files in folder

You can set a reference to the Scripting library, and manipulate the FileSystemObject to retrieve the DateLastModified property of any or all folders/files in VBA.

An làmb a bheir, 's i a gheibh.

RE: Get modified date on files in folder

Here's a function you can use to get the last modified date of a file.  You don't need to set a reference:

CODE

Function GetLastModDate(strFilePathAndName As String) As Date
    Dim fso As Object
    Dim f As Object
    
    Set fso = CreateObject("Scripting.FileSystemObject")
    
    Set f = fso.GetFile(strFilePathAndName)
    GetLastModDate = f.DateLastModified
    

    Set fso = Nothing
End Function

You just call it like

MsgBox GetLastModDate("C:\Temp\MyFile.xls")

and there you go.

Bob Larson
Free Access Tutorials and Samples: http://www.btabdevelopment.com

RE: Get modified date on files in folder

(OP)
Thanx bob
Your code works great on 1 specific file in a path, but I'd it to look thru all the files in the path.

 

RE: Get modified date on files in folder

Have a look at the For Each...Next construct in Access Help.

An làmb a bheir, 's i a gheibh.

RE: Get modified date on files in folder

So jammerdk -

What do you want as output?  How are you going to be using this information?  If you provide the answers to those questions I might have an idea on how to modify the code appropriately.

Bob Larson
Free Access Tutorials and Samples: http://www.btabdevelopment.com

RE: Get modified date on files in folder

Here is some of my code that I copied & pasted.
You will need to set the lib reference for this, but you may be able to modify it to suit your needs:

CODE

Dim fso As Scripting.FileSystemObject
Dim fol As Scripting.Folder
Dim fdr As Scripting.Folder
Dim fil As Scripting.File
Dim flc As Scripting.Folders

Set fso = CreateObject("Scripting.FileSystemObject")
Set fol = fso.GetFolder("YourPathName")
Set flc = fol.SubFolders

For Each fdr In flc

  For Each fil In fdr.Files
        Debug.Print fil.DateLastModified
  Next fil

Next fdr

Set fso = Nothing
Set fol = Nothing
Set flc = Nothing

An làmb a bheir, 's i a gheibh.

RE: Get modified date on files in folder

genomen:

If you make a small change you DON'T need to set a reference.
Change this:

CODE

Dim fso As Scripting.FileSystemObject
Dim fol As Scripting.Folder
Dim fdr As Scripting.Folder
Dim fil As Scripting.File
Dim flc As Scripting.Folders

to this:

CODE

Dim fso As Object
Dim fol As Object
Dim fdr As Object
Dim fil As Object
Dim flc As Object

No other changes necessary to make it run without references.

Bob Larson
Free Access Tutorials and Samples: http://www.btabdevelopment.com

RE: Get modified date on files in folder

sorry - genomon (not genomen - typo - sorry about that)

Bob Larson
Free Access Tutorials and Samples: http://www.btabdevelopment.com

RE: Get modified date on files in folder

Good point! For some reason I was locked into early-binding objects at a young age. Used to save overhead "back in the day". Don't think it's much of an issue anymore, although let's not turn this thread into a discussion of early vs. late.
wink
 

An làmb a bheir, 's i a gheibh.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close