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

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-01 14:09:03

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!