Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create Index Files 2

Status
Not open for further replies.

SMHSleepy

Technical User
Sep 8, 2009
174
CA
Hello all, I'm trying to complete a project and need one last step. I have a folder containing a bunch of picture files, each of which require a corresponding index file (plain text) in order to be fed into the appropriate location of a separate database.

The file names of the picture files contain all the necessary information. For example: 12-24-2011_987654321_MainReport.tif

For this example, the index file should have the following contents:

12/24/2011
987654321
MainReport
12-24-2011_987654321_MainReport.tif

The name of the index file should be:
IND.12-24-2011_987654321_MainReport.txt

Can someone suggest some VBA code to automate the creation of these index files? Thank you in advance.
 
What have you tried so far and where in your code are you stuck ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Unfortunately, I'm stuck at the start. I'm not a programmer but somewhat capable of figuring out existing code and changing it to apply to my needs. In fact, the example above is a simplified version of what I really need. I assume it should start with a count of the number of files in the folder, then a loop to read each file name, extract the information from the file name, and write each line of text. Can I get a push start here?
 
There is a really old solution for grabbing file names from a directory at Rogers Access Library. I think a more up to date solution would involve the FileSystemObject library. You might want to google this.

You can also use a loop with the Dir() function to get file names.

Try some of this an come back when you need more direction.

Duane
Hook'D on Access
MS Access MVP
 

TT members usually do not provide code, but ...
(Code not tested.)
Code:
Option Explicit
Private Const strMyPath As String = [red]"C:\PathToYour\Tiff_Files\"[/red]

Private Sub cmdJustDoIt_Click()
Dim strMyFile As String
Dim a() As String
[green]
'    12-24-2011_987654321_MainReport.tif
'IND.12-24-2011_987654321_MainReport.txt
[/green]
strMyFile = Dir(strMyPath & "\*.tif")

Do While strMyFile <> ""
    a = Split(strMyFile, "_")

    Open strMyPath & "IND." & Replace(strMyPath, ".tif", ".txt") For Output As #1
    Print #1, Replace(a(0), "-", "/")[green]
    '12/24/2011[/green]
    Print #1, a(1)[green]
    '987654321[/green]
    Print #1, Replace(a(2), ".tif", "")[green]
    'MainReport[/green]
    Print #1, strMyFile[green]
    '12-24-2011_987654321_MainReport.tif[/green]
    Close #1
    
    strMyFile = Dir
Loop

End Sub

Have fun.

---- Andy
 
Andy said:
TT members usually do not provide code
Somebody better tell MajP ;-)

I will typically provide code once an OP has made enough effort to provide the necessary significant background information and maybe tried something first.


Duane
Hook'D on Access
MS Access MVP
 

Duane, I totally agree with you, but since Mr. Sleepy said:
SMHSleepy said:
the example above is a simplified version of what I really need
I thought I would get him started. :)

Have fun.

---- Andy
 
Thank you Andy!

This is exactly what I need. I have to use a bunch of left, right, mid, and instr commands because it's not just a simple split but that should be easy.

Duane, I understand your view on this but Andy saved me a bunch of trial and error with FSO coding which frankly looks much more complicated.

I promise to try and make a valiant effort first next time! [bigsmile]



 
Very nice.

Little error on the following line:
Open strMyPath & "IND." & Replace(strMyPath, ".tif", ".txt") For Output As #1

Which should be:
Open strMyPath & "IND." & Replace(strMyFile, ".tif", ".txt") For Output As #1

Thanks again for the code! I can myself using this in many more applications.
 

Good catch :)
Like I said - this code was not tested. I just 'pull it out from my hat...' :)
I am glad you found it helpful


Have fun.

---- Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top