![]() |
listing file attributes
There are lots of posts about listing the contents of a folder and I've got
that. But I'd like some of the file attributes too (Title, Subject, Comments etc) and I haven't found a clear posting about that. The opinion seems to be that you should use FileSystemObject scripting but that's all new territory for me. I found this: Set fso = CreateObject("Scripting.FileSystemObject") Set Folder = fso.GetFolder("C:\DRIVERS") i = 1 For Each file In Folder.Files Sheets(1).Cells(i, 1) = file.Name i = i + 1 Next which works and a list of the file properties that should be available (0 = name, 1 = size, 10 = Title etc.) but I don't know how to combine the two snippets of info. Can anyone help? -- David M WinXP - Office2003 (Italian) |
listing file attributes
David,
If you use early binding rather than late binding, you can use IntelliSense to find out the specific properties available from the file object. For example, set a reference to MS Scripting Runtime, then use code like Option Explicit Dim fso As Scripting.FileSystemObject Dim Folder As Scripting.Folder Dim myFile As Scripting.File Sub TryNow() Dim i As Integer i = 1 Set fso = New Scripting.FileSystemObject Set Folder = fso.GetFolder("C:\DRIVERS") For Each myFile In Folder.Files Sheets(1).Cells(i, 1) = myFile.Name Sheets(1).Cells(i, 2) = myFile.DateCreated Sheets(1).Cells(i, 3) = myFile.DateLastAccessed Sheets(1).Cells(i, 4) = myFile.DateLastModified Sheets(1).Cells(i, 5) = myFile.Size Sheets(1).Cells(i, 6) = myFile.Type i = i + 1 Next myFile End Sub When you type myFile. you will get the intellisense list of available properties and methods for the myFile File object HTH, Bernie MS Excel MVP "#DIV/0" wrote in message ... There are lots of posts about listing the contents of a folder and I've got that. But I'd like some of the file attributes too (Title, Subject, Comments etc) and I haven't found a clear posting about that. The opinion seems to be that you should use FileSystemObject scripting but that's all new territory for me. I found this: Set fso = CreateObject("Scripting.FileSystemObject") Set Folder = fso.GetFolder("C:\DRIVERS") i = 1 For Each file In Folder.Files Sheets(1).Cells(i, 1) = file.Name i = i + 1 Next which works and a list of the file properties that should be available (0 = name, 1 = size, 10 = Title etc.) but I don't know how to combine the two snippets of info. Can anyone help? -- David M WinXP - Office2003 (Italian) |
listing file attributes
Hi Bernie,
Sorry for not getting back earlier. The properties/attributes I can access using this method don't seem to include those I was particularly after - title, comments, subject. There's an available property "Attributes" but I can't get that to actually produce anything. -- David M WinXP - Office2003 (Italian) "Bernie Deitrick" wrote: David, If you use early binding rather than late binding, you can use IntelliSense to find out the specific properties available from the file object. For example, set a reference to MS Scripting Runtime, then use code like Option Explicit Dim fso As Scripting.FileSystemObject Dim Folder As Scripting.Folder Dim myFile As Scripting.File Sub TryNow() Dim i As Integer i = 1 Set fso = New Scripting.FileSystemObject Set Folder = fso.GetFolder("C:\DRIVERS") For Each myFile In Folder.Files Sheets(1).Cells(i, 1) = myFile.Name Sheets(1).Cells(i, 2) = myFile.DateCreated Sheets(1).Cells(i, 3) = myFile.DateLastAccessed Sheets(1).Cells(i, 4) = myFile.DateLastModified Sheets(1).Cells(i, 5) = myFile.Size Sheets(1).Cells(i, 6) = myFile.Type i = i + 1 Next myFile End Sub When you type myFile. you will get the intellisense list of available properties and methods for the myFile File object HTH, Bernie MS Excel MVP "#DIV/0" wrote in message ... There are lots of posts about listing the contents of a folder and I've got that. But I'd like some of the file attributes too (Title, Subject, Comments etc) and I haven't found a clear posting about that. The opinion seems to be that you should use FileSystemObject scripting but that's all new territory for me. I found this: Set fso = CreateObject("Scripting.FileSystemObject") Set Folder = fso.GetFolder("C:\DRIVERS") i = 1 For Each file In Folder.Files Sheets(1).Cells(i, 1) = file.Name i = i + 1 Next which works and a list of the file properties that should be available (0 = name, 1 = size, 10 = Title etc.) but I don't know how to combine the two snippets of info. Can anyone help? -- David M WinXP - Office2003 (Italian) |
All times are GMT +1. The time now is 10:23 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com