Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to easily parse file paths in portable class libraries?

I'm needing to parse a path into parts from within a portable class library and get things like the filename, extension, just directory name, etc.

All of these methods are fairly easy to access from within System.IO.Path, however, this doesn't seem to exist within portable class libraries. Is there an open source replacement for this or some other API that would give me the same functionality?

like image 964
Earlz Avatar asked Jan 29 '13 18:01

Earlz


People also ask

What is PCL project?

PCL projects target specific profiles that support a known set of BCL classes/features. However, the down side to PCL is that they often require extra architectural effort to separate profile specific code into their own libraries.


2 Answers

You may be able to use or adapt the code for System.IO.Path from Mono: https://github.com/mono/mono/blob/master/mcs/class/corlib/System.IO/Path.cs

EDIT: Also, my PCL Storage library provides some file IO APIs to PCLs, including PortablePath.Combine().

like image 92
Daniel Plaisted Avatar answered Oct 22 '22 03:10

Daniel Plaisted


I would use Uri class

var segments = new Uri("file://c:/dir1/dir2/a.txt").Segments

which is supported by PCL

http://msdn.microsoft.com/en-us/library/system.uri.aspx

like image 28
I4V Avatar answered Oct 22 '22 04:10

I4V