Hello!
Here's routine from TurboPower iPRO component pack which I improved a bit
{ Set properties from Unix style line of directory listing }
procedure TIpFtpFileInfo.UnixStyleParse(Info : TStringList);
var
S, A : string;
i, idx : Integer;
wYear, wMonth, wDay, wHour, wMin, shit: Word;
fs: TFormatSettings;
begin
// Get defaults for file creation date/time
DecodeDate(GetTimeFn, wYear, wMonth, wDay);
DecodeTime(GetTimeFn, wHour, wMin, shit, shit);
{File Type}
S := Info[0];
case UpCase(S[1]) of
'-' : FFileType := ftFile;
'D' : FFileType := ftDir;
//'L' : FFileType := ftLink;
'L' : FFileType := ftDir;
else
FFileType := ftUnknown;
end;
{Owner Permissions}
FPermissions.Owner := [];
A := UpperCase(Copy(S, 2, 3));
if CharPos('R', A) > 0 then {!!.02}
FPermissions.Owner := FPermissions.Owner + [faRead];
if CharPos('W', A) > 0 then {!!.02}
FPermissions.Owner := FPermissions.Owner + [faWrite];
if CharPos('X', A) > 0 then {!!.02}
FPermissions.Owner := FPermissions.Owner + [faExecute];
{Group Permissions}
FPermissions.Group := [];
A := UpperCase(Copy(S, 5, 3));
if CharPos('R', A) > 0 then {!!.02}
FPermissions.Group := FPermissions.Group + [faRead];
if CharPos('W', A) > 0 then {!!.02}
FPermissions.Group := FPermissions.Group + [faWrite];
if CharPos('X', A) > 0 then {!!.02}
FPermissions.Group := FPermissions.Group + [faExecute];
{Other Permissions}
FPermissions.Other := [];
A := UpperCase(Copy(S, 8, 3)); {!!.02}
if CharPos('R', A) > 0 then
FPermissions.Other := FPermissions.Other + [faRead];
if CharPos('W', A) > 0 then {!!.02}
FPermissions.Other := FPermissions.Other + [faWrite];
if CharPos('X', A) > 0 then {!!.02}
FPermissions.Other := FPermissions.Other + [faExecute];
{Search index of date property - to avoid owner/group bad data}
// Date field always starts with 3-letter month name
GetLocaleFormatSettings(LANG_ENGLISH, fs);
idx:=0;
for i := 1 to Info.Count-1 do
if AnsiIndexStr(Info[i],fs.ShortMonthNames)<>-1 then
begin idx:=i; Break; end;
if idx=0 then Exit;
// Get other fields relative to Date
{Owner}
if (idx-3 > 0) then
FOwner := Info[idx-3];
{Group}
if (idx-2 > 0) then
FGroup := Info[idx-2];
{Size}
if (idx-1 > 0) then
FSize := StrToIntDef(Info[idx-1], 0);
{Time stamp}
if (idx <= Info.Count + 2) then
// parse timestamp. got it from Indy :)
// format: "Feb 27 19:07" or "Sep 20 2001", that is, |
begin
FTimeStamp := Info[idx] + ' ' + Info[idx+1] + ' ' + Info[idx+2];
i:=AnsiIndexStr(Info[idx],fs.ShortMonthNames);
if i>=0 then wMonth := i+1;
wDay := StrToIntDef(Info[idx+1], wDay);
i:=Pos(':', Info[idx+2]);
if i = 0 then // Not time info, scan year
begin
wYear := StrToIntDef(Info[idx+2], wYear);
wHour := 0;
wMin := 0;
end
else
begin // Time info, correct year, scan hour, min
if MonthOf(GetTimeFn) < wMonth then
Dec(wYear);
wHour:= StrToIntDef(Copy(Info[idx+2],1,i-1),0);
wMin := StrToIntDef(Copy(Info[idx+2],i+1,Length(Info[idx+2])),0);
end;
FDateCreated := EncodeDate(wYear, wMonth, wDay) + EncodeTime(wHour, wMin,
0, 0);
end;
{File name}
FFileName := '';
for i := idx+3 to Info.Count-1 do begin
if(Info[i] = '->')then
break;
if (FFileName <> '') then
FFileName := FFileName + ' ';
FFilename := FFileName + Info[i];
end;
{Symbolic Link}
FLinkPath := '';
if (FFileType = ftLink) then begin
for i := 0 to Pred(Info.Count) do
if (Info[i] = '->') then
break;
if (i <= (Info.Count - 2)) then
FLinkPath := Info[i + 1];
end;
end;
Moreover, I created more powerful & robust ICS FTP client descendant with Unix,
VMS, DOS listing parsing. Let me know if someone's interested.
--
Anton
--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be