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

I CANT FIND How to have the location of a file! (Not So Easy) 2

Status
Not open for further replies.

ozgurtekin

Programmer
Apr 22, 2003
17
TR
I want to have the location of a file

BUT

I want its location according to another file(this file's location can change).

For example suppose I have a web sites tags open. I add an image on this site with tags with the program I did with Delphi.

img src="File destination"

I want the file destination to be image.jpg not C:\Documents\image.jpg. Because It's in the same directory.
I can only have the second one with the help of OpenPicture Dialog.

If you help thanks
 
I'm not sure I understand what you want to do? Can you use the OpenDialog.FileName property? I think this provides a full path. You can then replace the filename with your filename via string parsing or by using a function like ExtractFilePath

Brian
"There are 2 kinds of people in the world, those that divide people into two groups and those that don't. I belong to the second group." - tag line I stole
 
You know how to build a web page, right?
The thing is:

It shows the file like this

img src="C:\askldj\aslknd.jpg" although the picture is in the same directory as the web page.
I only want the name of the file in this case. Another thing is that If the picture is in a subdirectory then I want the file path like this img src="images/asd.jpg"

Thats hard to tell and understand

 
You need the relative path of the image file. First, get the path name where the web page is located. Make sure it ends with a backslash (myPath). Then take the complete filename of the image file (imgFileName).
if pos(myPath,imgFileName) = 1 then
System.Delete(imgFileName,1,Length(myPath));
This will give you the required relative path in imgFileName.
 
Do you mean by "get the path" is having the directory like "C:\My documents\" or full name of it?

And file name only the "name" like "pic.jpg"?

I also want to have the final name data in Tedit

 
you have to use

ExtractRelativePath

synatax is
ExtractRelativePath(const BaseName, DestName: string): string;

where basename is name of your root directory
destname is name of your image file or any other file

eg

procedure TForm1.Button1Click(Sender: TObject);
var filename,Myrootdirectory:string;
begin

Myrootdirectory:='C:\Inetpub\
if OpenDialog1.Execute then filename:=OpenDialog1.filename;

showmessage(ExtractRelativePath(Myrootdirectory,filename));
end;




VERY IMPORTANT - the last \ at the end of the base name
 
This is ok
But
How can I get the root directory (C:\my documents\Something\) by using the openDialog. Which means I want to identify the root directory with opening an html. The root will be the dir the html page is in. Is that possible?

 
How can I get the directory of a file. (not the path but path-filename)
Ex:
'C:\Borland\'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top