======wish this help======
1. 在返回的时间中,如果返回没有年份,就是说明此文件是当
天存的,年份应该与你的机器是一样的。
2. 将字符的月份转化成数值
3. 分割由空格分开的字符串
4. 如何判断是目录还是文件,就是第一个字母为'd'就是目录。
其它我认为是文件。
5. 忽略当然目录和父目录,以及'total'字符串在这里只处理了文件与目录,用户与组别不考虑(似乎用不上)
日期我用了字符串表示,'yyyy/mm/dd' TFileAttr=(faDir,fafile);
PTFileInfo=^TFileInfo;
TFileInfo=record
FAttr:TFileAttr;
FLen:integer;
FFileName:string;
FDate:string;
end;函数如下:
procedure SetListString(var n:TFileInfo;s:string);
var
tempstr,ps:string; function getsubstr(var s:string):string;
var
k,l:integer;
begin
l:=length(s);
for k:=1 to l do
if s[k]<>' ' then break;
s:=copy(s,k,l-k+1);
l:=length(s);
for k:=1 to l do
begin
if s[k]=' ' then break;
end;
result:=copy(s,1,k-1);
s:=copy(s,k+1,l-k);
end;
begin
tempstr:=s;
with n do
begin
ps:=getsubstr(tempstr);
if ps='total' then exit;
if ps[1]='d' then FAttr:=faDir //目录
else Fattr:=fafile; //文件 ps:=getsubstr(tempstr);
ps:=getsubstr(tempstr);
ps:=getsubstr(tempstr);
FLen:=strtoint(getsubstr(tempstr));
FDate:=formatdatetime('yyyy',date);
ps:=getsubstr(tempstr);
FDate:=changemonth(ps);
ps:=getsubstr(tempstr);
FDate:=FDate+'/'+ps;
ps:=getsubstr(tempstr);
if pos(':',ps)>0 then
FDate:=formatdatetime('yyyy',date)+'/'+FDate
else
FDate:=ps+'/'+FDate;
FFileName:=getsubstr(tempstr);
end;
end;//转换月份
function ChangeMonth(month:string):string;
begin
result:='';
month:=uppercase(month);
if month='JAN' then result:='01'
else if month='FEB' then result:='02'
else if month='MAR' then result:='03'
else if month='APR' then result:='04'
else if month='MAY' then result:='05'
else if month='JUN' then result:='06'
else if month='JUL' then result:='07'
else if month='AUG' then result:='08'
else if month='FEB' then result:='09'
else if month='OCT' then result:='10'
else if month='NOV' then result:='11'
else if month='DEC' then result:='12';
end;
//在ftplistitem事件中调用函数 在这里使用的是TNMFTP控件
procedure TForm1.ftpListItem(Listing: String);
begin
addremotefile(listing);
end;procedure TForm1.Addremotefile(f:string);
var
myfileinfo:PTFileInfo;
begin
new(myfileinfo);
with myfileinfo^ do
begin
setliststring(myfileinfo^,f);
if (Ffilename='.') or (ffilename='..') //忽略'.'与'..'目录
or (ffilename='') then
begin
dispose(myfileinfo);
exit;
end;
...
end;
==========adopt from dfw offlinet database=======
1. 在返回的时间中,如果返回没有年份,就是说明此文件是当
天存的,年份应该与你的机器是一样的。
2. 将字符的月份转化成数值
3. 分割由空格分开的字符串
4. 如何判断是目录还是文件,就是第一个字母为'd'就是目录。
其它我认为是文件。
5. 忽略当然目录和父目录,以及'total'字符串在这里只处理了文件与目录,用户与组别不考虑(似乎用不上)
日期我用了字符串表示,'yyyy/mm/dd' TFileAttr=(faDir,fafile);
PTFileInfo=^TFileInfo;
TFileInfo=record
FAttr:TFileAttr;
FLen:integer;
FFileName:string;
FDate:string;
end;函数如下:
procedure SetListString(var n:TFileInfo;s:string);
var
tempstr,ps:string; function getsubstr(var s:string):string;
var
k,l:integer;
begin
l:=length(s);
for k:=1 to l do
if s[k]<>' ' then break;
s:=copy(s,k,l-k+1);
l:=length(s);
for k:=1 to l do
begin
if s[k]=' ' then break;
end;
result:=copy(s,1,k-1);
s:=copy(s,k+1,l-k);
end;
begin
tempstr:=s;
with n do
begin
ps:=getsubstr(tempstr);
if ps='total' then exit;
if ps[1]='d' then FAttr:=faDir //目录
else Fattr:=fafile; //文件 ps:=getsubstr(tempstr);
ps:=getsubstr(tempstr);
ps:=getsubstr(tempstr);
FLen:=strtoint(getsubstr(tempstr));
FDate:=formatdatetime('yyyy',date);
ps:=getsubstr(tempstr);
FDate:=changemonth(ps);
ps:=getsubstr(tempstr);
FDate:=FDate+'/'+ps;
ps:=getsubstr(tempstr);
if pos(':',ps)>0 then
FDate:=formatdatetime('yyyy',date)+'/'+FDate
else
FDate:=ps+'/'+FDate;
FFileName:=getsubstr(tempstr);
end;
end;//转换月份
function ChangeMonth(month:string):string;
begin
result:='';
month:=uppercase(month);
if month='JAN' then result:='01'
else if month='FEB' then result:='02'
else if month='MAR' then result:='03'
else if month='APR' then result:='04'
else if month='MAY' then result:='05'
else if month='JUN' then result:='06'
else if month='JUL' then result:='07'
else if month='AUG' then result:='08'
else if month='FEB' then result:='09'
else if month='OCT' then result:='10'
else if month='NOV' then result:='11'
else if month='DEC' then result:='12';
end;
//在ftplistitem事件中调用函数 在这里使用的是TNMFTP控件
procedure TForm1.ftpListItem(Listing: String);
begin
addremotefile(listing);
end;procedure TForm1.Addremotefile(f:string);
var
myfileinfo:PTFileInfo;
begin
new(myfileinfo);
with myfileinfo^ do
begin
setliststring(myfileinfo^,f);
if (Ffilename='.') or (ffilename='..') //忽略'.'与'..'目录
or (ffilename='') then
begin
dispose(myfileinfo);
exit;
end;
...
end;
==========adopt from dfw offlinet database=======
解决方案 »
- 弱弱的问个很简单的问题
- INDY TCP文件传输问题(急求,在线等)
- 请教关于listview的问题
- 庆祝阿甘生日(穷人散分)
- ★100分求救,如何给计算机添加IP地址
- 请问如何检测计算机中是否装有Modem,并判断是连接在哪个串口上?
- 请问怎样用adoquery实现在它的上一次查找结果中再查找?
- 在StringGrid中如何控制那一列是否只读,还有如何使焦点只能停在一行的其中一列上??
- 求解: 关于一个from 嵌套多个form(动态创建),请斑竹和其他高手帮忙确实有点麻烦,详细请看内容!
- 两个窗体,一个已经最小化,要求点击另一个窗体时可以将他还原(不是最大化)
- 如何解决:Insufficient memory for this operation.
- 100分求收据打印(套打)问题解答(代码)?
procedure TFtpForm.NMFTP1ListItem(Listing: String);
var
a:tlistitem;
begin
a:=listview1.Items.Add;
a.caption:=copy(listing,60,length(listing)-50);//文件名
if pos('d',listing)=1 then
a.subitems.add('<Dir>')//目录
else
a.subitems.add('File');//文件
a.subitems.add(copy(listing,47,13));//日期
a.subitems.add(inttostr(strtoint(copy(listing,30,16))));//长度
end;