The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM



Thread: absolute path
View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #5 (permalink)  
Old 06-05-2007
Perderabo's Avatar
Perderabo Perderabo is offline
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,718
If you are in, ahem, /directoryb (sorry, but I hate calling directories "folders"), you can call getcwd() to obtain "/directoryb". Since "../directorya/filea" does not start with a /, it must be a relative path. So prepend your current directory to it to get "/directoryb/../directorya/filea" which is an absolute path to the file in question. You could parse this to remove "/.." and the word preceding "/.." if you really need to simplify the path. But no matter what you do, it is possible for files to have multiple absolute paths that do not involve ".." due to symbolic links and loopback mounts.
Reply With Quote