Re: absolute path to relative path conversion
From: Rob Levine (rob_levine_at_hotmail.SPAMPROOF.com)
Date: 01/13/05
- Next message: Jay B. Harlow [MVP - Outlook]: "Re: Need a way to tell if a System.Windows.Forms.Button is "depressed" (pushed down)"
- Previous message: Geoff Jones: "Q: A MFC DLL being called from c#"
- In reply to: Rizaan Jappie: "Re: absolute path to relative path conversion"
- Next in thread: Rizaan Jappie: "Re: absolute path to relative path conversion"
- Reply: Rizaan Jappie: "Re: absolute path to relative path conversion"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 13 Jan 2005 14:30:57 GMT
Hi Rizaan,
If I understand correctly, what you are trying to do is easy in the example
you give as you are effectively just after the filename:
FileInfo fi = new FileInfo ( abPath ); // get a FileInfo for the file
specified in the absolute path
string relPath = fi.Name; // the name property returns the unqualified name
of the file
However, if the file you are after is in another directory then this is
quite a lot harder. I can't think of a way off the top of my head without
doing some sort of 'directory walk'.
You could walk from you absolute path to the root of your drive and then
walk down the path to your file, building the relative path as you go along.
This would work, but may not give you the most concise relative path
possible.
I am still not 100% sure I have understood what you are trying to do though.
Is it possible that the file you are after is in a different directory to
the absolute path given? Are you trying to build a relative path between a
directory and a file in another?
Apologies if it is obvious what you are saying and I am just missing the
point !
Rob
"Rizaan Jappie" <rizaanj@korbitec.com> wrote in message
news:em$iOdX%23EHA.1076@TK2MSFTNGP10.phx.gbl...
> Sorry for being so vague Rob
>
> what i need is the following :
>
> If i have an absolute path to a file e.g.
> c:\rizaan\pathsquestion\absolutepath\class1.cs
>
> how would i go about getting the relative path in c# for class1.cs using
> 'c:\rizaan\pathsquestion\absolutepath\' as the source directory?
>
> does this make sense at all?
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!
- Next message: Jay B. Harlow [MVP - Outlook]: "Re: Need a way to tell if a System.Windows.Forms.Button is "depressed" (pushed down)"
- Previous message: Geoff Jones: "Q: A MFC DLL being called from c#"
- In reply to: Rizaan Jappie: "Re: absolute path to relative path conversion"
- Next in thread: Rizaan Jappie: "Re: absolute path to relative path conversion"
- Reply: Rizaan Jappie: "Re: absolute path to relative path conversion"
- Messages sorted by: [ date ] [ thread ]