ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Getting FileSystem Date (https://www.excelbanter.com/excel-programming/439074-getting-filesystem-date.html)

PcolaITGuy

Getting FileSystem Date
 
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!

Steve Yandl[_3_]

Getting FileSystem Date
 
There are three properties to get dates from files or folders. I suspect
you want the first one listed below.

DateCreated
DateLastAccessed
DateLastModified


Steve Yandl

"PcolaITGuy" wrote in message
...
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 Lynn B

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

"PcolaITGuy" wrote:

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!


PcolaITGuy

Getting FileSystem Date
 
Thanks very much for the advice. It worked great.!

"B Lynn B" wrote:

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

"PcolaITGuy" wrote:

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!



All times are GMT +1. The time now is 02:09 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com