高手能否讲讲,或者给个例程?
解决方案 »
- ServerSocket很不稳定
- 关于指向数据的指针
- TVarData 与 tagVariant 有何不同?
- 试题库系统开发求助
- dbtext与sql表的联接,请帮手,TKS!
- 请问我怎样动态的远程获得ClientDataSet的DataSetProvider
- 简单的动态多维数组问题
- mvb2211 请来领分(1)
- delphi 中如何判断一个*.ocx 或 *.dll是否注册....
- 请大侠指点:怎样解决:“Couldn't perform the edit because another user changed the record."??
- 求用Delphi实现的FTP服务器端程序
- 刚刚升级到borland官方网站的Delphi 2006的update1,问:为什么Delphi 2006完整支持VB.net开发????
var
FindData:TWin32FindData;
hFindfile:Cardinal;
tFile:string;
NewItem:TListItem;
begin
if sPath[Length(sPath)]<>'\' then
sPath:=sPath+'\';
hFindfile:=FindFirstFile(pchar(sPath+sFileName),FindData);
if hFindfile=Invalid_Handle_Value then
Exit;
repeat
tFile:=FindData.cFileName;
if tFile[1]='.' then //如果是 .. 或 .则从头开始
Continue;
if FindData.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY then
FindAll(spath+tfile+'\',sFileName,lstView)
else begin
NewItem:=lstView.Items.Add;
NewItem.Caption:=tFile;
NewItem.SubItems.Add(sPath);
NewItem.SubItems.Add(IntToStr(FindData.nFileSizeLow));
end; until FindNextFile(hFindfile,FindData)=False;
Windows.FindClose(hFindfile);
end;
procedure TForm1.btn3Click(Sender: TObject);
begin
Findall('C:\windows\system32','*.*',lv1);
end;
var sr: TSearchRec;
FileAttrs: Integer;
Ret:Integer;
begin
FileAttrs := faReadOnly + faHidden+ faSysFile+ faVolumeID+ faDirectory+faArchive+faAnyFile;
Ret:=FindFirst(FPath+'*.*', FileAttrs, sr);
while Ret = 0 do begin
//是目录
if (sr.Attr and faDirectory) = faDirectory then begin
if (sr.Name<>'.') and (sr.Name<>'..') then begin
GetPromptVoxList(SLFile,FPath+sr.Name+'\');
end;
end else begin
//是文件
SLFile.Add(FPath+sr.Name);
end;
Ret:=FindNext(sr);
end;
FindClose(sr);
end;
------------------------------------------------------
我认为现在的核心问题的应该怎么样判断某一条item是文件还是文件夹.下面是FTP下载的过程,它会根据选中的是文件还是文件夹进行不同的处理.使用的idFtp组件.procedure TFTPclients.Btn_downloadClick(Sender: TObject);
var
strpath:string;
begin
if not CreateDirectory(Edt_path.Text) then
begin
showmessage('文件夹未'+Edt_path.Text+'新建成功');
end;
if FTPclient.Connected then
begin
FTPclient.List(nil);
if FTPclient.DirectoryListing[lbx_face.ItemIndex].ItemType = ditDirectory then
downloadDir(FTPclient,Edt_Crtpath.Text,Edt_path.Text)
else
begin
strpath:= edt_path.Text+FTPclient.DirectoryListing[lbx_face.ItemIndex].FileName;
FTPclient.Get(FTPclient.DirectoryListing[lbx_face.ItemIndex].FileName,strpath,true);
application.MessageBox('下载成功','提示',0);
end;
end;
end;
-------------------------------------
FTPclient.DirectoryListing[lbx_face.ItemIndex].ItemType 我们注意到它有个属性来记录ITEM是文件夹还是文件,这样我们操作起来就超级简单了.所以,哪位高手能帮我解决怎样判断item是文件夹还是文件,这个问题就解决了,不知道哪位高手有什么高招,谢谢
用下面的代码测试;type
TForm1 = class(TForm)
lv1: TListView;
btn3: TButton;
procedure btn3Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
procedure FindAll(sPath,sFileName:string;lstView:TListView);
public
{ Public declarations }
end;
procedure TForm1.FormCreate(Sender: TObject);
var
NewColumn:TListColumn;
begin
with lv1 do begin
if Assigned(Columns) then
Columns.Clear;
if Assigned(Items) then
Items.Clear;
NewColumn:=Columns.Add;
NewColumn.Caption:='File Name';
NewColumn.Width:=100;
NewColumn:=Columns.Add;
NewColumn.Caption:='File Path';
NewColumn.Width:=300;
NewColumn:=Columns.Add;
NewColumn.Caption:='File Size';
NewColumn.Width:=50;
end;
end;procedure TForm1.FindAll(sPath,sFileName:string;lstView:TListView);
var
FindData:TWin32FindData;
hFindfile:Cardinal;
tFile:string;
NewItem:TListItem;
begin
if sPath[Length(sPath)]<>'\' then
sPath:=sPath+'\';
hFindfile:=FindFirstFile(pchar(sPath+sFileName),FindData);
if hFindfile=Invalid_Handle_Value then
Exit;
repeat
tFile:=FindData.cFileName;
if tFile[1]='.' then //如果是 .. 或 .则从头开始
Continue;
if FindData.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY then
FindAll(spath+tfile+'\',sFileName,lstView)
else begin
NewItem:=lstView.Items.Add;
NewItem.Caption:=tFile;
NewItem.SubItems.Add(sPath);
NewItem.SubItems.Add(IntToStr(FindData.nFileSizeLow));
end; until FindNextFile(hFindfile,FindData)=False;
Windows.FindClose(hFindfile);
end;procedure TForm1.btn3Click(Sender: TObject);
begin
Findall('C:\windows','*.*',lv1);
end;
var sr: TSearchRec;
FileAttrs: Integer;
Ret:Integer;
begin
FileAttrs := faReadOnly + faHidden+ faSysFile+ faVolumeID+ faDirectory+faArchive+faAnyFile;
Ret:=FindFirst(FPath+'*.*', FileAttrs, sr);//注意这里,要求传入的目录名最后一个字符是\号,可能
while Ret = 0 do begin
//是目录
if (sr.Attr and faDirectory) = faDirectory then begin
if (sr.Name<>'.') and (sr.Name<>'..') then begin
GetList(SLFile,FPath+sr.Name+'\');
end;
end else begin
//是文件
SLFile.Add(FPath+sr.Name);
end;
Ret:=FindNext(sr);
end;
FindClose(sr);
end;
var SL1:TStringList;
begin
SL1:=TStringList.Create;
GetList(SL1,'C:\Downloads\');
Memo1.Lines.AddStrings(sl1);
sl1.Free;
end;