Getting FileSystem Date

P

PcolaITGuy

I found the code below to read a directory and list the filenames and bytes
into a worksheet. This is great but I also need the file system date for
each file. For the life of me I cannot find the correct property to use.
Here's the code I have that essentially won't give me the file date:

Sub GetAttributes()
On Error Resume Next
Dim FolderPath 'Path to search for files
Dim objFSO 'fileSystemObject
Dim objFolder 'folder object
Dim colFiles 'Collection of files from files method
Dim objFile 'individual file object
Dim ws
Dim x
FolderPath = "C:\batchtest\" ' File Path

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(FolderPath)
Set colFiles = objFolder.Files
Set ws = ActiveWorkbook.Worksheets(1)
x = 1
For Each objFile In colFiles
ws.Cells(x, 1).Value = objFile.Name
ws.Cells(x, 2).Value = objFile.Date
x = x + 1
Next
End Sub


Thanks in advance!
 
B

B Lynn B

Instead of objFile.date, you probably want objFile.DateLastModified or
objFile.DateCreated
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top