473,739 Members | 5,405 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Relative path to absolute

4 New Member
Hi there.

I'm writing a program under Linux. I need a function that convert relative path to absolute (or full path). Under Windows, I have a GetFullPathName function in WinAPI. But now, I need function for Linux (glibc may be).

Can someone help me?

P.S. Googling, googling... nothing found ;-(
Jan 6 '09 #1
2 19323
ashitpro
542 Recognized Expert Contributor
yes....
you are after "realpath". ..
Expand|Select|Wrap|Line Numbers
  1. #include <limits.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. int main()
  5. {
  6.         char resolved_path[100];
  7.         realpath("../../", resolved_path);
  8.         printf("\n%s\n",resolved_path);
  9.         return 0;
  10. }
  11.  
Jan 6 '09 #2
mac11
256 Contributor
Another option, if you're using c++ anyway, is to use boost::filesyst em. It provides portable file system stl-like objects.

Boost C++ Libraries
Jan 6 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

15
2906
by: Nick K. | last post by:
I recently began maintenance work on a production web server that is located in the root directory of a web server. I moved this into a sub web on my local web server in order to do work on it. I found that there is an include file that references images: <img src = "/images/Header.gif" What worked correctly on the production server breaks on mine because of the absolute address "/images". I removed the absolute address and changed...
4
27728
by: Richard | last post by:
We are distributing a VS2003 solution to our customers that includes a .NET assembly (dll file) and a sample project for how to use the dll. The customer can then customize the sample or add a new project to the solution. The problem is that the customers cannot simply take the solution we distribute and build it. VS2003 is saving the reference to the dll as an fully qualified absolute path (not relative to the project), so after...
7
78642
by: Rizaan Jappie | last post by:
is it possible to get the relative path based on a absolute path in c#? *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
0
1946
by: Ffelagund | last post by:
There are any Path or Directory function to convert an absolute path to a relative path using a choiced directory as base to calculate the origin of the relative path?
6
11770
by: openleren | last post by:
Hi all, how can I use a relative path in my web.config file for an Access db?: Instead of using <configuration> <appSettings> <add key="conAccess" value="microsoft.jet.oledb.4.0;data source=c:/Inetpub/MyApp/data/database.mdb" /> ...
4
9724
by: Boni | last post by:
Is there something already done to get absolute path from relative path, and relative path from absolute path: Example: BasePath="c:\a\b\c" RelativePath="..\e\f\g\..\m" AbsolutePath=FindAbsolutePath(BasePath, RelativePath) and the same in other direction
0
1280
by: Nick | last post by:
Hi, I need to strong name my application and thus have to specify the sn key path in the <Assembly: AssemblyKeyFile("strongNameKey.snk")> parameter. Observations: If I specify the hardcoded absolute path, things work absolutely fine. However if I try and specify a relative path, things go askew and I end up with Build errors stating that the sn key file cannot be found. On googling,
19
5102
by: Jerry M. Gartner | last post by:
Greetings: What is the best way to resolve paths within a document regardless of what path it is opened under? For example: I have x.php and it contains <img src="images...">, (amongst other things, like php code), which resolves the correct image path when opened under / but when x.php is read into a file under /dir the image no longer resolves, for obvious reasons. With absolute paths, this isn't an issue but it is with relative...
2
15759
by: =?Utf-8?B?ZmFpcnl2b2ljZQ==?= | last post by:
hi, i just want to know when i new a Uri instance using the UriKind.Relative para in construtor, where is the root path, for example, a local file Uri u=new Uri("a.txt",UriKind.Relative); then where is it? I thought it would be in the "object\debug" directory where the exe file exists but nope Can anyone tell me? I just want to get some local file using Uri with relative path. Thx in advanced
1
1429
by: ahmed786 | last post by:
Hello , I am a new in PHP.I have a task to resolve realtive path to absolute path. for example : ../default/test.png -> /image/default/test.png I have done it with string replace function.but,this is not the solution.I need to resolve the relative path with base path such as /home/domainusers/workspace/picfinder/image/default/test.png. It's also possible the relative path would be like this "test.png".I have to resolve this also with...
0
8969
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8792
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9479
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9209
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8215
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6054
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3280
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.