Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Path separators

Status
Not open for further replies.

forrestcupp

Programmer
Jul 22, 2006
25
0
0
I know this is kind of a crazy question, but in Python when I make a string with a path to a file, I can use os.sep which means that if it is being used in Windows it's the "\" character and in Linux/unix it's the "/" character. Is there anything like this in c#?

The reason I'm asking is because .NET is being used in Linux now, and it would make cross-platform stuff a little easier.
 
Have a look at this link:

The author says you should be able to use Environment.PathSeparator - but in my VS2005 C# Express edition I have at home, 'System.Environment' does not contain a definition for 'PathSeparator'


[sub]~LFCfan
who is gnawing on the knowledge[/sub]
 
// Get the platform specific path separator.
char chPathSep = Environment.PathSeparator;

// Get the platform specific director separator.
char chDirSep = Environment.DirectorySeparatorChar;

// Get the platform specific volume separator character.
char chVolSep = Environment.VolumeSeparatorChar;
 
Thank you. Actually it was the DirectorySeparatorChar that I was looking for, but mine doesn't have it either. I wonder why.
 
I suppose you are using Mono. Take a look at System.IO.Path class...

Path.AltDirectorySeparatorChar
Path.DirectorySeparatorChar

Hope this helps
 
Thank you alphanytz. That is what I was looking for. I assume that on Linux the Path.DirectorySeparatorChar would be '/', and that I wouldn't have to distinguish between this and Path.AltDirectoryChar?
 
Yes Linux uses forward slash as directoy separator, and based on the docs, both properties return the same separator.

[wink]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top