473,320 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Reading filenames and file properties in a directory

waynetheengineer
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
4 20699
SammyB
807 Expert 512MB
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
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
807 Expert 512MB
> 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
Killer42
8,435 Expert 8TB
Thanks for that, Sammy. This looks like another entry for the Tips & Tricks, when I have time.
Apr 20 '07 #5

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

Similar topics

9
by: hokiegal99 | last post by:
This script works as I expect, except for the last section. I want the last section to actually remove all spaces from the front and/or end of filenames. For example, a file that was named " test ...
1
by: Joel Goldstick | last post by:
I wanted to write a simple page to let me choose a directory and then list the files in it. The end goal was to make an easy way to copy all the file names in a directory. I tested with Opera7,...
8
by: Tim | last post by:
Does anyone know a way to read the filenames from a given directory in C in a Solaris environment? I did this, but it seems goofy: sprintf(t, "ls *.csv > filenames.txt"); system(t); fptr =...
2
by: rbutch | last post by:
guys, i need a little help with this. this is working (well sort of) i get the info, but it's not moving to a new line as it iterates thru the array and all of the fields are like ONE HUGE LONG...
6
by: I_AM_DON_AND_YOU? | last post by:
I have a small VB.Net Solution. The solution has filename LABELMAKER.SLN and the the project has filename LABELMAKER.VBPROJ. There is another file LABELMAKER.VBPROJ.USER. All these are in a...
22
by: rtilley | last post by:
# Spaces are present before and after the XXX filename = ' XXX ' new_filename = filename.strip() if new_filename != filename: print filename Macs allow these spaces in file and folder...
2
by: Taras_96 | last post by:
Hi everyone, Firstly, I would like to know if you can open chinese filenames under win2000 using PHP 5.0? I have a file named 中国.php, and try to open it using fopen(‘中国.php','r');....
3
by: Joakim Hove | last post by:
Hello, I am reading a filename from the user - the loop is typically like this: 1. Read a directory from the user. 2. Read several filenames from the user. The filenames read in 2. above...
2
by: Manogna | last post by:
hi! all, in a directory nearly 10 zipped file are available. totally the size of the all files is nearly 15GB. i have to retrive the line which dont have the text "ORA" from each file...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.