目录不晓得在哪个盘,哪个目录下? 可以使用递归查找系统的所有驱动器算法可以在网上找到 或者:(只是方法,你还要修改一下的) procedure TForm1.MakeTree; var Sr : TSearchRec; Err: integer; s, TrSize, FilePath : string; Begin Application.ProcessMessages; Err:=FindFirst('*.*',$37,Sr) ; While (Err = 0) do begin if Sr.Name[1]<>'.' then begin FilePath:=ExpandFileName(Sr.Name); TreeSize:=TreeSize+Sr.Size; TrSize:=FloatToStr(TreeSize); ScanProgress.Caption:=sr.Name; if (maxcount<1) or (searchcount<=maxcount) then begin s:=extractfilepath(filepath)+sr.Name; if ExtList.Items.Count=0 then inc(searchcount) else if ExtList.Items.IndexOf('.*')>-1 then begin form2.Memo1.Lines.Add(s+' '+inttostr(sr.size)+' Bytes'); SearchSize:=SearchSize+sr.Size; inc(searchcount); end else if ExtList.Items.IndexOf(AnsiLowerCase(extractfileext(sr.name)))>-1 then begin if DelFile.Checked then if DelToRecycled(s) then form2.Memo1.Lines.Add('Delete !!!! '+s+' '+inttostr(sr.size)+' Bytes') else form2.Memo1.Lines.Add('Delete fail '+s+' '+inttostr(sr.size)+' Bytes') else form2.Memo1.Lines.Add(s+' '+inttostr(sr.size)+' Bytes'); SearchSize:=SearchSize+sr.Size; inc(searchcount); end; end; if (Sr.Attr and faDirectory)=0 then begin FilesSize:=FilesSize+Sr.Size; inc(FilesCount); end; inc(TreeCount); end; { Begin Recursion } If ((Sr.Attr and faDirectory)<>0)AND(Sr.Name[1] <> '.') then begin DirsSize:=DirsSize+Sr.Size; inc(DirsCount); ChDir(Sr.Name) ; MakeTree ; ChDir('..') ; end ; { End Recursion } Err:=FindNext(Sr) ; end ; End;procedure TForm1.ScanButtonClick(Sender: TObject); begin TreeCount:=1; FilesCount:=0; DirsCount:=0; TreeSize:=0; FilesSize:=0; DirsSize:=0; Searchcount:=0; SearchSize:=0; form2.Memo1.Clear; ChDir(DirectoryListBox1.Directory); screen.Cursor:=crhourglass; MakeTree; screen.Cursor:=crdefault; Form2.Show; end;
TShellListView
or
第三方的
TPTShellList
setcurrentdir返回的是bool值。。
我就是不晓得怎么去指定一个不知在哪个盘哪个地方的目录,只晓得要显示的文件在目录名为:abc下,怎么办?怎样指定指定目录后FileListBox1.refresh 内的值不变呀!
配合ExtractFilePath,ParamStr(0)等就可以定位相对目录的我还不清楚你的意图
Getcurrentdir获得当前目录
ExtractFilePath获得当前路径
有问题请发信息到我的E-mail:[email protected]
可以使用递归查找系统的所有驱动器算法可以在网上找到
或者:(只是方法,你还要修改一下的)
procedure TForm1.MakeTree;
var Sr : TSearchRec;
Err: integer;
s, TrSize, FilePath : string;
Begin
Application.ProcessMessages;
Err:=FindFirst('*.*',$37,Sr) ;
While (Err = 0) do
begin
if Sr.Name[1]<>'.' then
begin
FilePath:=ExpandFileName(Sr.Name);
TreeSize:=TreeSize+Sr.Size;
TrSize:=FloatToStr(TreeSize);
ScanProgress.Caption:=sr.Name;
if (maxcount<1) or (searchcount<=maxcount) then
begin
s:=extractfilepath(filepath)+sr.Name;
if ExtList.Items.Count=0 then inc(searchcount) else
if ExtList.Items.IndexOf('.*')>-1 then
begin
form2.Memo1.Lines.Add(s+' '+inttostr(sr.size)+' Bytes');
SearchSize:=SearchSize+sr.Size;
inc(searchcount);
end else
if ExtList.Items.IndexOf(AnsiLowerCase(extractfileext(sr.name)))>-1 then
begin
if DelFile.Checked then
if DelToRecycled(s)
then form2.Memo1.Lines.Add('Delete !!!! '+s+' '+inttostr(sr.size)+' Bytes')
else form2.Memo1.Lines.Add('Delete fail '+s+' '+inttostr(sr.size)+' Bytes')
else form2.Memo1.Lines.Add(s+' '+inttostr(sr.size)+' Bytes');
SearchSize:=SearchSize+sr.Size;
inc(searchcount);
end;
end;
if (Sr.Attr and faDirectory)=0 then
begin
FilesSize:=FilesSize+Sr.Size;
inc(FilesCount);
end;
inc(TreeCount);
end; { Begin Recursion }
If ((Sr.Attr and faDirectory)<>0)AND(Sr.Name[1] <> '.') then
begin
DirsSize:=DirsSize+Sr.Size;
inc(DirsCount);
ChDir(Sr.Name) ;
MakeTree ;
ChDir('..') ;
end ;
{ End Recursion }
Err:=FindNext(Sr) ;
end ;
End;procedure TForm1.ScanButtonClick(Sender: TObject);
begin
TreeCount:=1;
FilesCount:=0;
DirsCount:=0;
TreeSize:=0;
FilesSize:=0;
DirsSize:=0;
Searchcount:=0;
SearchSize:=0;
form2.Memo1.Clear;
ChDir(DirectoryListBox1.Directory);
screen.Cursor:=crhourglass;
MakeTree;
screen.Cursor:=crdefault;
Form2.Show;
end;