请问关于这个FTP目录表的正则筛选是什么意思

一品梅 2017-08-18 10:35:17
 /// <summary>
/// Gets the files or directories from the specified directory.
/// </summary>
/// <param name="directory">The directory.</param>
/// <param name="type">The type.</param>
/// <returns>
/// An enumeration of <see cref="FlagFtp.FtpFileSystemInfo"/> with the type of the specified type argument.
/// </returns>
private IEnumerable<FtpFileSystemInfo> GetFileSystemInfos(Uri directory, FtpFileSystemInfoType type)
{
if (directory == null)
throw new ArgumentNullException("directory");

if (directory.Scheme != Uri.UriSchemeFtp)
throw new ArgumentException("The directory isn't a valid FTP URI", "directory");

using (var response = (this.CreateResponse(directory, WebRequestMethods.Ftp.ListDirectoryDetails)))
{
using (Stream responseStream = response.GetResponseStream())
{
using (var reader = new StreamReader(responseStream))
{
string all = reader.ReadToEnd();

//这个正则没大看懂。
var regex = new Regex(@"^(?<FileOrDirectory>[d-])(?<Attributes>[rwxts-]{3}){3}\s+\d{1,}\s+.*?(?<FileSize>\d{1,})\s+(?<Date>\w+\s+\d{1,2}\s+(?:\d{4})?)(?<YearOrTime>\d{1,2}:\d{2})?\s+(?<Name>.+?)\s?$",
RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);

MatchCollection matches = regex.Matches(all);

var infos = matches.Cast<Match>()
.Select(
match =>
new
{
IsDirectory = match.Groups["FileOrDirectory"].Value == "d",
...全文
1464 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuzuning 2017-08-19
  • 打赏
  • 举报
回复
你把 all 打印出来就知道了 ^(?<FileOrDirectory>[d-])(?<Attributes>[rwxts-]{3}){3}\s+\d{1,}\s+.*?(?<FileSize>\d{1,})\s+(?<Date>\w+\s+\d{1,2}\s+(?:\d{4})?)(?<YearOrTime>\d{1,2}:\d{2})?\s+(?<Name>.+?)\s?$ FileOrDirectory、Attributes、FileSize、Date、YearOrTime、Name 望文生义,没有理解障碍
一品梅 2017-08-19
  • 打赏
  • 举报
回复
对FTP的ListDirectoryDetails所产生的界面也不熟悉,望帮忙结合分析一下。

8,497

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 LINQ
社区管理员
  • LINQ
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧