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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extract Path from FileName 1

Status
Not open for further replies.

LT2

MIS
May 24, 2006
232
US
Using CRXI w/SQL Svr

Hi,

I would like to know how to display just the path portion of the filename.

I changed the Syntax to Basic in the Formula Editor, but CRXI doesn't like the formula. It doesn't seem to recognize 'GetFilePath':

@ReportPath
'Retrieve a file's path without the trailing back slashes
'To include colons in the result

Function GetFilePath (FileName As String) as String
Dim i as Long
For i = Len(FileName) To 1 Step -1
Select Case Mid$(FileName, i, 1)
Case ":"
GetFilePath = Left$(FileName, i)
Exit For
Case "\"
GetFilePath = Left$(FileName, i -1)
Exit For
Next
End Function

Is there a way to do this using Crystal Syntax?

I was able to extract the File from FileName using:

@ReportFileName
StringVar Array File:=Split (Filename, '\');
NumberVar i := Ubound(File);
File;

But I can't figure out how to get just the path.

Your help would be greatly appreciated.

LT

 
Hi,
With this formula
Code:
@ReportFileName
StringVar Array File:=Split (Filename, '\');
NumberVar i := Ubound(File);
File[i];

You have all the elements of the file name..try looping through the array members from 1 to i - you should be able to extract the location parts if they are part of Filename.



[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 
Hi Turkbear,

I don't know how to do what you're suggesting. I changed to:

@ReportPath
StringVar Array Path:= Split (Filename, '\');
NumverVar i ;= Ubound(Path);
Path [1];

The results only display the drive letter 'C:'. How do I make it show me the entire path?

LT
 
I did kskid, but this just displays the name of the file.

LT
 
When I changed the the formula to:

StringVar Array Path:= Split (Filename, '\');
NumverVar i ;= Ubound(Path);
Path [1]+':'+ Path [2]+':'+ Path [3]+':'+ Path [4]+':'+ Path [5]+':'+ Path [6]+':'+ Path [7]+':'+ Path [8]+ Path [9]':';

The entire path was displayed with colons. But not every report will have this dimension. Is there a way to make this dynamic so it will display all but the file name?

LT
 
On the second line of the formula, you have a ";=" when you should have a ":=".

Try this more compact version of the formula:
Code:
StringVar Array Path:= Split (Filename, '\');
Path[Ubound(Path)]

~Brian
 
Try this:

left(filename, instrrev(filename,"\")-1)

-LB
 
Excellent LB. It runs nice and clean.

Here's my end solution:

StringVar FullFilePath := FileName;
Left(FullFilePath,Instrrev(FullFilePath,'\'-1);


Thanks to all who helped me with this one.
LT
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top