如题。
解决方案 »
- 如何获取指定目录下的目录名列表
- 微软最新的VISTA系统不支持DELPHI吗?
- 数据库代码字段的显示问题
- 谁有《〈delphi5开发指南>>,我需要(非电子版本),南京,13357831456(短信联系)
- 关于 ClientDataSet 的分析
- 如何用ado连接加密的ACCESS数据库?
- Activex控件在Delphi中的使用问题
- ado 中MSJET40怪问题及其它,请教各位
- SocketConnection.Appserver(参数:Olevariant) 如何使参数是一个记录类型的数据
- Delphi中的publish相当于VC中的protected吗??
- delphi中自带的database desktop的问题,求教
- 第三次问:Delphi中如何把二进制流保存到一个xml节点中去?up有分!
var
Dir: TSearchRec;
Ret: integer;
Path: string;
begin
Result := 0;
Path := ExtractFilePath(ADirectory);
Ret := Sysutils.FindFirst(ADirectory, faAnyFile, Dir);
if Ret<>0 then
begin
ShowMessage('路径输入错误');
exit;
end; try
while ret=0 do
begin
inc(Result, Dir.Size);
if (Dir.Attr in [faDirectory]) and (Dir.Name[1] <> '.') then
Inc(Result, GetDirectorySize(Path + Dir.Name + '\*.*'));
Ret := Sysutils.FindNext(Dir);
end;
finally
Sysutils.FindClose(Dir);
end;
end;
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, FileCtrl, ComCtrls, ExtCtrls;type
TForm1 = class(TForm)
Button1: TButton;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
Panel1: TPanel;
ListView1: TListView;
Panel2: TPanel;
Button2: TButton;
Edit1: TEdit;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure IniListView();
procedure ListView1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure ListView1DblClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
function GetDirectoryName(Dir:String):String; //ÉèÖÃDIR
procedure FindFiles(APath:String); //²éÕÒÖ÷º¯Êý end;var
Form1: TForm1;
Dir1:string;
pathpos:integer;
selectpath:string;
implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
//winexec('rundll32.exe shell32.dll,Control_RunDLL Intl.cpl,,0',9);
close;
end;procedure TForm1.Button2Click(Sender: TObject);
begin
SelectDirectory('Select Directory', '', Dir1);
if Dir1<>'' then
begin
edit1.Text:=Dir1;
ListView1.Items.Clear;
FindFiles(Dir1);
end;
end;procedure TForm1.IniListView();
var
NewColumn: TListColumn;
begin
with ListView1 do
begin
Parent := panel1;
Align := alClient;
OnClick := ListView1Click; // <- ¼ÓÉÏÕâ¾ä ViewStyle := vsReport; NewColumn := Columns.Add;
NewColumn.Caption := 'ËزÄÃû³Æ';
NewColumn.Width:=100;
NewColumn := Columns.Add;
NewColumn.Caption := 'ÎļþÀàÐÍ';
NewColumn.Width:=100;
NewColumn := Columns.Add;
NewColumn.Caption := '·¾¶';
NewColumn.Width:=200;
NewColumn := Columns.Add;
NewColumn.Caption := 'Îļþ´óС';
NewColumn.Width:=100;
NewColumn := Columns.Add;
NewColumn.Caption := '¸üÐÂʱ¼ä';
NewColumn.Width:=100; end;
end;function Tform1.GetDirectoryName(Dir:String):String; //ÉèÖÃDIR
begin
if Dir[LengTh(Dir)]<>'\' then
Result:=Dir+'\'
else
Result:=Dir;
end;procedure Tform1.FindFiles(APath:String); //²éÕÒÖ÷º¯Êý
var
FSearchRec,DsearchRec:TSearchRec;
FindResult:integer;
it:tlistitem;
fhandle:thandle;
hip:pointer;
filesize:longint;
/////////
tempstr:string;
function IsDirNotation(ADirName:String):Boolean;
begin
Result:=(ADirName='.') or(ADirName='..')or(ADirName='') ;
End;begin
Apath:=GetDirectoryName(APath);
FIndResult:=FindFirst(APath+'*.*',faAnyFile+faHidden+faSysFile+FaReadonly,FsearchRec);
Try
while FindResult=0 do
begin
it:=listview1.Items.Add;
it.Caption:=extractfilename(APath+FSearchRec.Name); //°Ñ²éÕÒµ½µÄÎļþÁгöÀ´
it.SubItems.Add(extractfileext(APath+FSearchRec.Name));//ÁгöÎļþµÄÎļþÀàÐÍ
it.SubItems.Add(APath+FSearchRec.Name); fhandle:=createfile(pchar(APath+FSearchRec.Name),GENERIC_READ,FILE_SHARE_READ,nil,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
new(hip);
filesize:=GetFileSize(fhandle,hip);
dispose(hip);
it.SubItems.Add(FormatFloat('#,000',filesize)+' ×Ö½Ú');
//»ñµÃËùѡ·¾¶ÒÔÏÂÎļþ·¾¶
//tempint:=pos(nowdir,copy(apath,pathpos,length(apath)-pathpos+1));
//tempstr:=copy(apath,tempint+pathpos,length(apath)-tempint-pathpos);
tempstr:=copy(apath,pathpos,length(apath)-pathpos+1);
it.SubItems.Add(selectpath+tempstr+it.Caption);
closehandle(fhandle);
FindResult:=FindNext(FSearchRec);
end;
FindReSult:=FindFirst(APath+'*.*',faDirectory,DSearchRec);
while FindResult=0 do
begin
if (DSearchRec.Attr{ and faDirectory)}=faDirectory) and not ISDirNotation(DSEarchRec.Name) then
FindFiles(APath+DsearchRec.Name);
FindResult:=FindNext(DsearchREc);
end;
Finally
FindClose(FSearchRec);
findclose(DsearchREc);
end;
end;procedure TForm1.ListView1Click(Sender: TObject);
begin
//hjfgh
end;procedure TForm1.FormShow(Sender: TObject);
begin
IniListView;
edit1.Text:=extractfilepath(Application.ExeName);
FindFiles(extractfilepath(Application.ExeName));
end;procedure TForm1.ListView1DblClick(Sender: TObject);
var
i:integer;
begin
if TListView(Sender).ItemIndex>=0 then // °ÑListView1¸ÄΪTListView(Sender)
begin
i:=TListView(Sender).ItemFocused.Index;
showmessage(ListView1.Items[i].SubItems[1])
end
end;end.
结贴吧~