解析 Windows FTP 服务器的文件详细信息
我正在尝试通过 C# 代码连接到 FTP 服务器,并且正在获取文件和目录列表。我将其保存在 ArrayList 中(包含所有属性)。我可以通过SYS ftp命令找到FTP服务器类型。我有一个基于 UNIX 的文件的正则表达式来解析文件\目录属性。但我没有对Windows FTP服务器文件解析的表达。我需要帮助来做到这一点......
04-30-09 10:40AM <DIR> Acrobat
12-08-09 10:36PM 9058 AuthCheck.zip
12-06-09 12:49PM 174 desktop.ini
11-09-09 03:33PM <DIR> FailedPDF
我需要解析这些。日期、时间、目录\文件、文件名
请帮忙。谢谢。
I am trying to connect to FTP server through the c# code and I am getting the list of Files and directories. And that I am saving in a ArrayList(with all attributes). I can find the FTP Server type through the SYS ftp command. I have a regular expression for UNIX based files to parse the file\directories attributes. But I have no expression for Windows FTP server files parsing. I need help in making that..
04-30-09 10:40AM <DIR> Acrobat
12-08-09 10:36PM 9058 AuthCheck.zip
12-06-09 12:49PM 174 desktop.ini
11-09-09 03:33PM <DIR> FailedPDF
I need to parse these. Date, Time, Dir\File, Name of the file
Please help. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我对 C# 不太了解,但如果你只需要一个正则表达式,请尝试这个:
^(\d\d-\d\d-\d\d)\s+(\d\d:\d \d(上午|下午))\s+([\w<>]*)\s+(\d*)\s+([\w\._\-]+)\s*$
$1 = 日期、$2=时间、$3=上午或下午、$4=类型(可以为空)、$5=大小(如果是目录则为空)、$6=名称
或当且仅当 $4 为空
^(\d\d -\d\d-\d\d)\s+(\d\d:\d\d(AM|PM))\s+(
)?\s+(\d*)\s+([\ w\._\-]+)\s*$
我想“<”和“>” c# 中没有特殊字符
I don't know much about C#, but if you just need a RegEx try this one:
^(\d\d-\d\d-\d\d)\s+(\d\d:\d\d(AM|PM))\s+([\w<>]*)\s+(\d*)\s+([\w\._\-]+)\s*$
$1 = date, $2=time, $3=am or pm, $4=type (could be null), $5=size(null if dir), $6=name
or iff $4 is only or empty
^(\d\d-\d\d-\d\d)\s+(\d\d:\d\d(AM|PM))\s+(<DIR>)?\s+(\d*)\s+([\w\._\-]+)\s*$
I suppose that "<" and ">" are no special chars at c#
捕获组:
0:日期时间
1:是目录
2:文件大小(或目录为空)
3:名称
我手边没有编译器,所以我无法测试它,但它应该足够接近以开始使用。
Capture groups:
0: datetime
1: Is dir
2: FileSize (or null for directory)
3: Name
I dont have a compiler handy so I cant test that, but it should be close enough to get started.
看起来线条有固定的结构。所以你可以简单地这样做:
It looks like the lines have fixed structure. So you could simply do this: