Extracting Text

  • Thread starter Thread starter Bre-x
  • Start date Start date
B

Bre-x

I have a table with one single text field.

S:\ENG\DATA\DWN\my file_1.pdf
S:\ENG\DATA\DWN\CUSTOMER\MSG\file.pdf
S:\ENG\DATA\DWN\CUSTOMER\My Subdir\my_other file.pdf

How do I extract the file name and the file path and save it on two text
fields?

the_path
S:\ENG\DATA\DWN
S:\ENG\DATA\DWN\CUSTOMER\MSG
S:\ENG\DATA\DWN\CUSTOMER\My Subdir

the_file
my file_1.pdf
file.pdf
my_other file.pdf

There are two constants: the file extension ".pdf" and the "S:\ENG\DATA\"

Thank you all

Bre-x
 
I have a table with one single text field.

S:\ENG\DATA\DWN\my file_1.pdf
S:\ENG\DATA\DWN\CUSTOMER\MSG\file.pdf
S:\ENG\DATA\DWN\CUSTOMER\My Subdir\my_other file.pdf

How do I extract the file name and the file path and save it on two text
fields?

the_path
S:\ENG\DATA\DWN
S:\ENG\DATA\DWN\CUSTOMER\MSG
S:\ENG\DATA\DWN\CUSTOMER\My Subdir

the_file
my file_1.pdf
file.pdf
my_other file.pdf

There are two constants: the file extension ".pdf" and the "S:\ENG\DATA\"

Thank you all

Bre-x

In A2002 (possibly 2003, I'm not certain) and later there's a function
InStrRev that will do this:

the_path: Left([fieldname], InStrRev([fieldname], "\") - 1)
the_file: Mid([fieldname], InStrRev([fieldname], "\") + 1)
 
Path: Left([YourTextField], InStrRev([YourTextField], "/"))
File: RightLeft([YourTextField], (Len([YourTextField])+1)
-[InStrRev([YourTextField], "/"))
 
Path: Left([YourTextField], InStrRev([YourTextField], "/"))
File: RightLeft([YourTextField], (Len([YourTextField])+1)
-[InStrRev([YourTextField], "/"))

Karl, is RightLeft something you wrote or a typo? Shouldn't that be just:

Mid([YourTextField], InStrRev([YourTextField], "\") + 1)

Note that the Mid() function gets the rest of the string after the position in
the second argument if the third argument is absent, so you don't need to
subtract from the length of the field.
 
Yes, I saw my typo after I read your first post.
--
Build a little, test a little.


John W. Vinson said:
Path: Left([YourTextField], InStrRev([YourTextField], "/"))
File: RightLeft([YourTextField], (Len([YourTextField])+1)
-[InStrRev([YourTextField], "/"))

Karl, is RightLeft something you wrote or a typo? Shouldn't that be just:

Mid([YourTextField], InStrRev([YourTextField], "\") + 1)

Note that the Mid() function gets the rest of the string after the position in
the second argument if the third argument is absent, so you don't need to
subtract from the length of the field.
 
Back
Top