FTP Parsing directory listings

G

Gina_Marano

Good day all,

Trying to get a listing of directories in a directory using FTP.

I get the following as a result:

"drw-rw-rw- 1 user group 0 Nov 2 18:39 testdir"

Anybody have a good regex expression or any ideas how I would parse
this to get "testdir" or any other method?

thanks a bunch

~Gina~
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Gina_Marano said:
Trying to get a listing of directories in a directory using FTP.

I get the following as a result:

"drw-rw-rw- 1 user group 0 Nov 2 18:39 testdir"

Anybody have a good regex expression or any ideas how I would parse
this to get "testdir" or any other method?

I had this old code on the shelf:

using System;

public class MainClass
{

public static string Eater(string line, int ix, int n)
{
string res = "";
int ws = 0;
for (int i = 1; i < line.Length; i++) {
if ((line == ' ') && (line[i - 1] != ' ')) {
ws = ws + 1;
}
if ((ws >= ix) && (ws < (ix + n))) {
res = res + line;
}
}
return res.Trim();
}

public static void Parse(string line)
{
string protection = Eater(line, 0, 1);
string owner = Eater(line, 1, 3);
int size = int.Parse(Eater(line, 4, 1));
string tim = Eater(line, 5, 3);
string filename = Eater(line, 8, 100);
Console.WriteLine(filename + " " + size + " " + tim);
}

public static void Main(string[] args)
{
Parse("drwxr-xr-x 1 ftp ftp 0 Sep 01 19:38 Adobe
Illustrator 10");
Parse("drwxr-xr-x 1 ftp ftp 0 Sep 07 09:36 subdir");
Parse("-rw-r--r-- 1 ftp ftp 1871872 Sep 07 11:52 a.zip");
Parse("-rw-r--r-- 1 ftp ftp 21814474 Sep 07 09:53 z.zip");
}
}

I am not sure it is perfect, but the 4 examples in main do work.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top