Using .foundfile

Lynsey

New member
Local time
Today, 03:00
Joined
Jun 15, 2000
Messages
6
I am writing a database which reads in data from a series of delimited text files. What I would like to do is show the user the files that are to be imported. I am using the file search property and I can get all my files and put them in my database but when I do a "For i = 1 To .foundfiles.Count" and then display the files being linked(.foundfiles(i)) it gives me the whole location as well, which I don't want. Any ideas?? I have looked at tons of examples and every one seems to return the location with the filename
redface.gif
(
 
Work out the result as a string. Use the Left/Right functions to cut the part that you need...
 
You need to find the last instance of the '\' character in the returned string, then keep only those characters to the right of it.

Access provides a function InStr, which will find the FIRST instance of a character in a string, but that's not much help, so I did it with a custom function to reverse the string, then the position (from left) of the first '\' in the reversed string is equivalent to the position (from right) in the original string, anyway, here's the reverse function:

Code:
Public Function reverse(yourstring As String)
Dim MyLoop As Integer
For MyLoop = Len(yourstring) To 1 Step -1
    reverse = reverse & Mid(yourstring, MyLoop, 1)
Next MyLoop
End Function

paste this into a new module in the modules tab of your database, then save the module.
then you can use an expression like this to get the last bit (filename only) of your string:

Right(strYourFileAndPathName, (InStr(reverse(strYourFileAndPathName), "\") - 1))

Hope this helps

Mike

[This message has been edited by Mike Gurman (edited 04-24-2001).]
 
Tip:
I have to do this sort of import thing a lot; I've found that the best way for me to handle the actual multiple import process was to have a folder with all of the files in it (say C:\files) and another folder C:\files\done, then you can:

-use the DIR function to find the first file
-import and process the file
-DoEvents
-use NAME to move the file from c:\files to c:\files\done
-repeat until DIR returns a null string

This way, you never import anything twice and if something fails later on, you still have all of the files in the 'done' folder.

HTH

Mike
 
You can write this:

filename= .Foundfiles(i)

newfilename=Left(filename,n)

Where n is the number of characters that you want to keep. Then you use newfilename to display the info to the user.
 

Users who are viewing this thread

Back
Top Bottom