解析FtpWebRequest ListDirectoryDe​​tails行 [英] Parsing FtpWebRequest ListDirectoryDetails line

查看:206
本文介绍了解析FtpWebRequest ListDirectoryDe​​tails行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#中解析来自 ListDirectoryDe​​tails 的响应需要一些帮助。



我只需要以下字段。


  • 文件名/目录名称

  • 创建日期

  • 和文件大小。



以下是运行 ListDirectoryDe​​tails $ b

  d  -  x  -  x  -  x 2 ftp ftp 4096 Mar 07 2002 bin 
-rw-r - r-- 1 ftp ftp 659450 Jun 15 05:07 TEST.TXT
-rw -r - r - 1 ftp ftp 101786380 Sep 08 2008 TEST03 -05.TXT
drwxrwxr-x 2 ftp ftp 4096 May 06 12:24 dropoff

解决方案

不知道你是否仍然需要这个,但这是我想出的解决方案:

  Regex regex = new Regex(@^([d  - ])([rwxt  - ] {3}){3} \ S + \d {1,} \s +。*?(\d {1,})\s +(\w + \s + \d {1,2} \s +(?: \d {4})?)(\d {1,2}:\d {2})?\s +(。+?)\s?$,
RegexOp tions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);

匹配组:


  1. 对象类型:


    • d:目录

    • - :file



    • 数组[3]权限(rwx - )

    • 最后修改日期
    • 上次修改时间

    • 文件/目录名称


I need some help with parsing the response from ListDirectoryDetails in C#.

I only need the following fields.

  • File Name/Directory Name
  • Date Created
  • and the File Size.

Here's what some of the lines look like when I run ListDirectoryDetails:

d--x--x--x    2 ftp      ftp          4096 Mar 07  2002 bin
-rw-r--r--    1 ftp      ftp        659450 Jun 15 05:07 TEST.TXT
-rw-r--r--    1 ftp      ftp      101786380 Sep 08  2008 TEST03-05.TXT
drwxrwxr-x    2 ftp      ftp          4096 May 06 12:24 dropoff

Thanks in advance.

解决方案

Not sure if you still need this, but this is the solution i came up with:

Regex regex = new Regex ( @"^([d-])([rwxt-]{3}){3}\s+\d{1,}\s+.*?(\d{1,})\s+(\w+\s+\d{1,2}\s+(?:\d{4})?)(\d{1,2}:\d{2})?\s+(.+?)\s?$",
    RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace );

Match Groups:

  1. object type:
    • d : directory
    • - : file
  2. Array[3] of permissions (rwx-)
  3. File Size
  4. Last Modified Date
  5. Last Modified Time
  6. File/Directory Name

这篇关于解析FtpWebRequest ListDirectoryDe​​tails行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆