Board index » delphi » changing relative paths into full paths

changing relative paths into full paths

hello,

i need to change the relative paths into full paths.
i searched for them inside a file and got these paths.

now i used this code to change them into full paths:

  if Pos('\', temp) = 0 then
  begin
    // add the path and replace it with the new value...
  end;

there are some problems. it changes all URLs into paths!

for example, the path that should be added to them is "C:"

myfile.txt            --> C:\myfile.txt
.\myfile.bat         --> ..\myfile.txt
www.mysite.com        --> C:\www.mysite.com
http://www.mysite.com --> C:\http://www.vidfern.7p.com

also i used GetFullPathName() function to do so, but the result
was as same as my code!

i think that it should be a function that helps me to change
all relative paths into full paths without changing URLs.

best regards,
Ted

 

Re:changing relative paths into full paths


Hello Ted,

Ted schrieb:

Quote
> i need to change the relative paths into full paths.
> i searched for them inside a file and got these paths.
[snip]
> there are some problems. it changes all URLs into paths!

Since You talked abaou *relative* path, You should have an Idea to what root they are relative!
There are several possibilities
- a local Program execution in a path (e.g.: c:\program files\myprog\myprog.exe) than the Path is relative to "c:\program files\myprog\"
- a Program execution followed by a ChDir, thatn the Program remains in its origin, but the Path changed e.g the Path may relative to "c:\my files\myprog\"
- Webserver/Client than Pathes expand to "<method>://<domainname>" see how Internet Addresses are build

You may notice that in the Internet Path separation is done with "Slash" while Windows does it with an "Backslash"

Quote
> for example, the path that should be added to them is "C:"

It should be "c:\", because "c:" is still relative

Quote
> myfile.txt            --> C:\myfile.txt

Ok,

Quote
> .\myfile.bat         --> ..\myfile.txt

Two mistakes here:
- ".\" is *not* the same than "..\" e.g. open a Dos-Box change to c:\Windows enter "dir .\config.sys" and "dir ..\config.sys", the last one will show "c:\config.sys" the first "c:\windows\config.sys" which normally is not there
- changing a *.bat into a *.txt file was not in the job

Quote
> www.mysite.com        --> C:\www.mysite.com

Why not? You *may* have a file on Your Computer with the Name "www.mysite.com" located in the "c:\" dir. The only way out is to Test if the file is there or not.

Quote
> http://www.mysite.com --> C:\http://www.vidfern.7p.com

???? why does the Domainname changed?
Here You can search if a Filename starts with "http://" You have nothing to do.

Quote
> also i used GetFullPathName() function to do so, but the result
> was as same as my code!

Sure.

Quote
> i think that it should be a function that helps me to change
> all relative paths into full paths without changing URLs.

If You can tell the funktion to work on local Files, it will be work.

Quote
> best regards,
> Ted

Best regards
Ekkehard
--
DomIS Internet Solution - Ekkehard Domning
Im "mCC": Industriestr. 17 - 49740 Haselnne
Mail: e...@domis.de Internet: http://www.domis.de

Other Threads