By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,649 Members | 696 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,649 IT Pros & Developers. It's quick & easy.

Reading filenames and file properties in a directory

waynetheengineer
P: 26
Hello everyone :)

I am trying to write VB code for reading filenames and file property values in a specific directory.

For example, I have a directory called C:/Bears and in that directory are three files: Brown Bears.txt, Black Bears.txt, and Orange Bears.txt. Each of these files have text descriptions in both the Title property field and the Comments property field of the each file (when you right click the file and select Properties, and then select the Summary tab and in there are many fields, two of wich are Title and Comments). I want to be able to loop through every file in this folder and do the following:

1) read the color of each bear from the filename itself (Brown, Black, and Orange), not the whole filename, into variables,

2) read the text from the Title property field of each file into variables, and

3) read the text from the Comments property field of each file into a variable.

Any suggestions?

Thanks!

Wayne.
Apr 19 '07 #1
Share this Question
Share on Google+
4 Replies


SammyB
Expert 100+
P: 807
Hello everyone :)

I am trying to write VB code for reading filenames and file property values in a specific directory.

For example, I have a directory called C:/Bears and in that directory are three files: Brown Bears.txt, Black Bears.txt, and Orange Bears.txt. Each of these files have text descriptions in both the Title property field and the Comments property field of the each file (when you right click the file and select Properties, and then select the Summary tab and in there are many fields, two of wich are Title and Comments). I want to be able to loop through every file in this folder and do the following:

1) read the color of each bear from the filename itself (Brown, Black, and Orange), not the whole filename, into variables,

2) read the text from the Title property field of each file into variables, and

3) read the text from the Comments property field of each file into a variable.

Any suggestions?

Thanks!

Wayne.
What VB are you using? From previous posts, I'm assuming VBA. You can open the text file via Word and use the BuiltInDocumentProperties method of the document. Other Office apps have the same method. HTH --Sam
Apr 19 '07 #2

waynetheengineer
P: 26
Hi, thanks for the reply.

I'm using Visual Basic 6.0.

I also need to read file properties of jpeg and other image files as well. Does this work with them too?

Thanks,
Wayne.

What VB are you using? From previous posts, I'm assuming VBA. You can open the text file via Word and use the BuiltInDocumentProperties method of the document. Other Office apps have the same method. HTH --Sam
Apr 20 '07 #3

SammyB
Expert 100+
P: 807
> I'm using Visual Basic 6.0.
Then just add a reference to Microsoft Word Object Library and open the file

>I also need to read file properties of jpeg and other image files as well. Does this work with them too?
They don't have a Summary tab, so the DocProperties will be blank. Word may complain when opening so I would set DisplayAlerts = False

But, with a little more searching, I found that Microsoft has a utility to help you read them w/o opening the files. See http://support.microsoft.com/?kbid=224351. Don't wory about the .Net stuff, it works in VB6 and the download comes with a VB6 example. Something like:
Expand|Select|Wrap|Line Numbers
  1. Dim oFilePropReader As New DSOleFile.PropertyReader
  2. Dim oDocProp As DSOleFile.DocumentProperties
  3. Dim sFile As String
  4. sFile = "C:\MyFolder\MyDocument.doc"
  5. Set oDocProp = oFilePropReader.GetDocumentProperties(sFile)
  6. MsgBox oDocProp.Author
  7. Set oDocProp = Nothing
  8. Set oFilePropReader = Nothing
Apr 20 '07 #4

Expert 5K+
P: 8,434
Thanks for that, Sammy. This looks like another entry for the Tips & Tricks, when I have time.
Apr 20 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.