Hi,
I'm retrieving a detailed list of files into a string array via FTP. Each item in the array looks something like this
"drwxr-x--- 3 vincent vincent 4096 Jul 12 12:16 public_ftp".
What would be the easiest way to break this info down and put it into the relevent columns on a listview control(name, date, attibutes etc). I'm really stuck on where to start.
appreciate any help
Chris

FTP list result
Kenshin1591
Ice2Fire
dickdunbar
Hi,
Thanks a lot for your help, your code has been very usefull to me. I was wandering how you deal with getting files that contain spaces in the file name
cheers,
Chris
Flippy_TK
NicolasP
public class ServerFileData
{
public bool isDirectory;
public string fileName;
public int size;
public string type;
public string date;
public string permission;
public string owner;
public string group;
public ServerFileData()
{
}
}
private ServerFileData ParseDosDirLine(string line)
{
ServerFileData sfd = new ServerFileData();
try
{
string[] parsed = new string[3];
int index = 0;
int position = 0;
// Parse out the elements
position = line.IndexOf(' ');
while (index<parsed.Length)
{
parsed[index] = line.Substring(0, position);
line = line.Substring(position);
line = line.Trim();
index++;
position = line.IndexOf(' ');
}
sfd.fileName = line;
if (parsed[2] != "<DIR>")
sfd.size = Convert.ToInt32(parsed[2]);
sfd.date = parsed[0]+ ' ' + parsed[1];
sfd.isDirectory = parsed[2] == "<DIR>";
}
catch
{
sfd = null;
}
return sfd;
}
private ServerFileData ParseUnixDirLine(string line)
{
ServerFileData sfd = new ServerFileData();
try
{
string[] parsed = new string
int index = 0;
int position;
// Parse out the elements
position = line.IndexOf(' ');
while (index<parsed.Length)
{
parsed[index] = line.Substring(0, position);
line = line.Substring(position);
line = line.Trim();
index++;
position = line.IndexOf(' ');
}
sfd.fileName = line;
sfd.permission = parsed[0];
sfd.owner = parsed[2];
sfd.group = parsed[3];
sfd.size = Convert.ToInt32(parsed[4]);
sfd.date = parsed[5]+ ' ' + parsed
sfd.isDirectory = sfd.permission[0] == 'd';
}
catch
{
sfd = null;
}
return sfd;
}
private void ParseUnixDirList(string sDir)
{
const string CRLF = "\r\n";
try
{
m_filecount = 0;
int i = 0;
sDir = sDir.Replace (CRLF, "\r");
string[] sFile = sDir.Split(new Char[]{'\r'});
ServerFileData sfd = null;
int autodetect = 0;
foreach (string fileLine in sFile)
{
if (autodetect == 0)
{
sfd = ParseDosDirLine(fileLine);
if (sfd == null)
{
sfd = ParseUnixDirLine(fileLine);
autodetect = 2;
}
else
autodetect = 1;
}
else
if (autodetect == 1)
sfd = ParseDosDirLine(fileLine);
else
if (autodetect == 2)
sfd = ParseUnixDirLine(fileLine);
if (sfd != null)
{
m_files
i++;
m_filecount = i;
}
}
}
catch (Exception e)
{
}
}
ssmorgan
Hi!
It looks like you have fixed length columns in line. So easiest way may be to SubString() from line.