问题
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?
回答1:
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()
.
回答2:
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
来源:https://stackoverflow.com/questions/14589795/is-there-a-way-to-easily-parse-file-paths-in-portable-class-libraries