简体   繁体   English

有没有办法轻松解析可移植类库中的文件路径?

[英]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. 所有这些方法都很容易从System.IO.Path中访问,但是,这似乎不存在于可移植类库中。 Is there an open source replacement for this or some other API that would give me the same functionality? 是否有这个或其他API的开源替代品可以提供相同的功能?

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 您可以使用或调整Mono的System.IO.Path代码: 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() . 编辑:此外,我的PCL存储库为PCL提供了一些文件IO API,包括PortablePath.Combine()

I would use Uri class 我会用Uri

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

which is supported by PCL 这是PCL支持的

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM