Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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! |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
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! |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
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! |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
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! |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How to read filesystem shortcut attributes | Excel Programming | |||
FileSystem.RMDIR | Excel Programming | |||
Filesystem again | Excel Programming | |||
To Bob Phillips ( Filesystem) | Excel Programming | |||
Filesystem again | Excel Programming |