Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Technology Project and PMC » Way to convert paths to OS Specific format?
Way to convert paths to OS Specific format? [message #58349] Mon, 29 September 2003 21:04 Go to next message
Eclipse User
Originally posted by: mharp.seapine.com

Hey all,

I've got the string "c:\fred\class1.java"

Is there some kind of static method or any other way to ask Eclipse to give
me back the path for the current platform that I'm on?

For example, on Windows it would give me back "c:\fred\class1.java" and
Linux would give me back "c:/fred/class1.java".

Thanks for any help you can provide,

harpstein
Re: Way to convert paths to OS Specific format? [message #58371 is a reply to message #58349] Tue, 30 September 2003 09:09 Go to previous messageGo to next message
Eclipse User
Originally posted by: bob.news.gmx.net

"Harpstein" <mharp@seapine.com> schrieb im Newsbeitrag
news:bla6i9$nlq$1@eclipse.org...
> Hey all,
>
> I've got the string "c:\fred\class1.java"
>
> Is there some kind of static method or any other way to ask Eclipse to
give
> me back the path for the current platform that I'm on?

I think that is not possible for a fundamental reason: When given a string
without further information the source system is unknown and thus the
convention for path separators is unknown.

A proper solution could use File.getName() and File.getParent() on the
source side to split up the complete path into a list of path components
(Strings) and then use File.File(File, String) to reconstruct it on the
target side.

> For example, on Windows it would give me back "c:\fred\class1.java" and
> Linux would give me back "c:/fred/class1.java".

This could easily be achieved by aPathString.replaceAll( "[/\\\\]", "\\" +
File.separatorChar ) but be warned that this is not a portable solution at
all.

Regards

robert
Re: Way to convert paths to OS Specific format? [message #58393 is a reply to message #58371] Tue, 30 September 2003 13:19 Go to previous message
Eclipse User
Originally posted by: mharp.seapine.com

Actually, I found the Path class which has a ctor that takes a raw string.
Then I just call toOSString and that seems to work for me.

Thanks,

harpstein

"Robert Klemme" <bob.news@gmx.net> wrote in message
news:blbh5m$s70$1@eclipse.org...
>
> "Harpstein" <mharp@seapine.com> schrieb im Newsbeitrag
> news:bla6i9$nlq$1@eclipse.org...
> > Hey all,
> >
> > I've got the string "c:\fred\class1.java"
> >
> > Is there some kind of static method or any other way to ask Eclipse to
> give
> > me back the path for the current platform that I'm on?
>
> I think that is not possible for a fundamental reason: When given a string
> without further information the source system is unknown and thus the
> convention for path separators is unknown.
>
> A proper solution could use File.getName() and File.getParent() on the
> source side to split up the complete path into a list of path components
> (Strings) and then use File.File(File, String) to reconstruct it on the
> target side.
>
> > For example, on Windows it would give me back "c:\fred\class1.java" and
> > Linux would give me back "c:/fred/class1.java".
>
> This could easily be achieved by aPathString.replaceAll( "[/\\\\]", "\\" +
> File.separatorChar ) but be warned that this is not a portable solution at
> all.
>
> Regards
>
> robert
>
Re: Way to convert paths to OS Specific format? [message #595446 is a reply to message #58349] Tue, 30 September 2003 09:09 Go to previous message
Robert Klemme is currently offline Robert Klemme
Messages: 14
Registered: July 2009
Junior Member
"Harpstein" <mharp@seapine.com> schrieb im Newsbeitrag
news:bla6i9$nlq$1@eclipse.org...
> Hey all,
>
> I've got the string "c:\fred\class1.java"
>
> Is there some kind of static method or any other way to ask Eclipse to
give
> me back the path for the current platform that I'm on?

I think that is not possible for a fundamental reason: When given a string
without further information the source system is unknown and thus the
convention for path separators is unknown.

A proper solution could use File.getName() and File.getParent() on the
source side to split up the complete path into a list of path components
(Strings) and then use File.File(File, String) to reconstruct it on the
target side.

> For example, on Windows it would give me back "c:\fred\class1.java" and
> Linux would give me back "c:/fred/class1.java".

This could easily be achieved by aPathString.replaceAll( "[/\\\\]", "\\" +
File.separatorChar ) but be warned that this is not a portable solution at
all.

Regards

robert
Re: Way to convert paths to OS Specific format? [message #595457 is a reply to message #58371] Tue, 30 September 2003 13:19 Go to previous message
Eclipse User
Originally posted by: mharp.seapine.com

Actually, I found the Path class which has a ctor that takes a raw string.
Then I just call toOSString and that seems to work for me.

Thanks,

harpstein

"Robert Klemme" <bob.news@gmx.net> wrote in message
news:blbh5m$s70$1@eclipse.org...
>
> "Harpstein" <mharp@seapine.com> schrieb im Newsbeitrag
> news:bla6i9$nlq$1@eclipse.org...
> > Hey all,
> >
> > I've got the string "c:\fred\class1.java"
> >
> > Is there some kind of static method or any other way to ask Eclipse to
> give
> > me back the path for the current platform that I'm on?
>
> I think that is not possible for a fundamental reason: When given a string
> without further information the source system is unknown and thus the
> convention for path separators is unknown.
>
> A proper solution could use File.getName() and File.getParent() on the
> source side to split up the complete path into a list of path components
> (Strings) and then use File.File(File, String) to reconstruct it on the
> target side.
>
> > For example, on Windows it would give me back "c:\fred\class1.java" and
> > Linux would give me back "c:/fred/class1.java".
>
> This could easily be achieved by aPathString.replaceAll( "[/\\\\]", "\\" +
> File.separatorChar ) but be warned that this is not a portable solution at
> all.
>
> Regards
>
> robert
>
Previous Topic:Way to convert paths to OS Specific format?
Next Topic:any tools for slicing and control flow analysis?
Goto Forum:
  


Current Time: Thu Oct 02 14:35:10 GMT 2014

Powered by FUDForum. Page generated in 0.02307 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software