问题2 如何列出某个文件夹下面的所有文件。比如我要找出D盘的AA文件夹下面的所有文件,如和做?
请高手 指点,先谢了!·
8 个解决方案
#1
用 filefindfirst ,filefindnext 等相关 api函数就可!!
#2
1.问题和2问题可以用相同的方法!
2.
procedure TForm1.Button1Click(Sender: TObject);
var
SearchRec:TSearchRec;
ext,AppPath:string;
begin
listbox1.Items.Clear;
AppPath:='d:\aa\';
ext:='*.*';
FindFirst(AppPath+ext,faAnyFile-faDirectory,SearchRec);
listbox1.Items.Add(SearchRec.Name);
while FindNext(SearchRec)=0 do
listbox1.Items.Add(SearchRec.Name);
listbox1.items为你需要的结果
end;
2.
procedure TForm1.Button1Click(Sender: TObject);
var
SearchRec:TSearchRec;
ext,AppPath:string;
begin
listbox1.Items.Clear;
AppPath:='d:\aa\';
ext:='*.*';
FindFirst(AppPath+ext,faAnyFile-faDirectory,SearchRec);
listbox1.Items.Add(SearchRec.Name);
while FindNext(SearchRec)=0 do
listbox1.Items.Add(SearchRec.Name);
listbox1.items为你需要的结果
end;
#3
源码如下,源码实现了在窗体关闭后将特定的文件删除:
procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
var
Fsearchrec:Tsearchrec;
findresult:integer;
begin
//=============================删除执行文件(假设为TT.exe)所在目录下的临时文件.
findresult:=findfirst(extractfilepath('TT.exe')+'*.tmp',faanyfile,Fsearchrec);
try
while findresult=0 do
begin
deletefile(extractfilepath('TT.exe')+fsearchrec.name);
findresult:=findnext(fsearchrec);
end;
finally
findclose(fsearchrec);
end;
//============================删除固定目录“c:\temp”下的扩展名为“.tmp”的临时文件.
{ findresult:=findfirst('c:\temp\'+'*.tmp',faanyfile,Fsearchrec);
try
while findresult=0 do
begin
deletefile('c:\temp\'+fsearchrec.name);
findresult:=findnext(fsearchrec);
end;
finally
findclose(fsearchrec);
end;}
//=============================
end;
“*.tmp”可用具体的文件名或其他通配符代换。
别忘了给我加分:)
procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
var
Fsearchrec:Tsearchrec;
findresult:integer;
begin
//=============================删除执行文件(假设为TT.exe)所在目录下的临时文件.
findresult:=findfirst(extractfilepath('TT.exe')+'*.tmp',faanyfile,Fsearchrec);
try
while findresult=0 do
begin
deletefile(extractfilepath('TT.exe')+fsearchrec.name);
findresult:=findnext(fsearchrec);
end;
finally
findclose(fsearchrec);
end;
//============================删除固定目录“c:\temp”下的扩展名为“.tmp”的临时文件.
{ findresult:=findfirst('c:\temp\'+'*.tmp',faanyfile,Fsearchrec);
try
while findresult=0 do
begin
deletefile('c:\temp\'+fsearchrec.name);
findresult:=findnext(fsearchrec);
end;
finally
findclose(fsearchrec);
end;}
//=============================
end;
“*.tmp”可用具体的文件名或其他通配符代换。
别忘了给我加分:)
#4
我给你第一个问题的例子,比如我要搜索d:\下的chenhu2目录,如下:
procedure TForm1.Button1Click(Sender: TObject);
var
SearchRec:TSearchRec;
apppath,ext:string;
begin
listbox1.Items.Clear;
AppPath:='d:\*.*';
ext:='chenhu2';
FindFirst(AppPath,faDirectory,SearchRec);
if SearchRec.Name=ext then
listbox1.Items.Add(SearchRec.Name);
while FindNext(SearchRec)=0 do
if SearchRec.Name=ext then
listbox1.Items.Add(SearchRec.Name);
// listbox1.items为你需要的结果
end;
procedure TForm1.Button1Click(Sender: TObject);
var
SearchRec:TSearchRec;
apppath,ext:string;
begin
listbox1.Items.Clear;
AppPath:='d:\*.*';
ext:='chenhu2';
FindFirst(AppPath,faDirectory,SearchRec);
if SearchRec.Name=ext then
listbox1.Items.Add(SearchRec.Name);
while FindNext(SearchRec)=0 do
if SearchRec.Name=ext then
listbox1.Items.Add(SearchRec.Name);
// listbox1.items为你需要的结果
end;
#5
那要是搜索d盘根目录呢?
#6
需要用递归过程对某个子目录全部遍历
#7
看看这个
http://haitian.myrice.com/Soft/MyPubFuncUnit.Txt
http://haitian.myrice.com/Soft/MyPubFuncUnit.Txt
#8
lhzwxt(lhcz_wxt)方法对
#1
用 filefindfirst ,filefindnext 等相关 api函数就可!!
#2
1.问题和2问题可以用相同的方法!
2.
procedure TForm1.Button1Click(Sender: TObject);
var
SearchRec:TSearchRec;
ext,AppPath:string;
begin
listbox1.Items.Clear;
AppPath:='d:\aa\';
ext:='*.*';
FindFirst(AppPath+ext,faAnyFile-faDirectory,SearchRec);
listbox1.Items.Add(SearchRec.Name);
while FindNext(SearchRec)=0 do
listbox1.Items.Add(SearchRec.Name);
listbox1.items为你需要的结果
end;
2.
procedure TForm1.Button1Click(Sender: TObject);
var
SearchRec:TSearchRec;
ext,AppPath:string;
begin
listbox1.Items.Clear;
AppPath:='d:\aa\';
ext:='*.*';
FindFirst(AppPath+ext,faAnyFile-faDirectory,SearchRec);
listbox1.Items.Add(SearchRec.Name);
while FindNext(SearchRec)=0 do
listbox1.Items.Add(SearchRec.Name);
listbox1.items为你需要的结果
end;
#3
源码如下,源码实现了在窗体关闭后将特定的文件删除:
procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
var
Fsearchrec:Tsearchrec;
findresult:integer;
begin
//=============================删除执行文件(假设为TT.exe)所在目录下的临时文件.
findresult:=findfirst(extractfilepath('TT.exe')+'*.tmp',faanyfile,Fsearchrec);
try
while findresult=0 do
begin
deletefile(extractfilepath('TT.exe')+fsearchrec.name);
findresult:=findnext(fsearchrec);
end;
finally
findclose(fsearchrec);
end;
//============================删除固定目录“c:\temp”下的扩展名为“.tmp”的临时文件.
{ findresult:=findfirst('c:\temp\'+'*.tmp',faanyfile,Fsearchrec);
try
while findresult=0 do
begin
deletefile('c:\temp\'+fsearchrec.name);
findresult:=findnext(fsearchrec);
end;
finally
findclose(fsearchrec);
end;}
//=============================
end;
“*.tmp”可用具体的文件名或其他通配符代换。
别忘了给我加分:)
procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
var
Fsearchrec:Tsearchrec;
findresult:integer;
begin
//=============================删除执行文件(假设为TT.exe)所在目录下的临时文件.
findresult:=findfirst(extractfilepath('TT.exe')+'*.tmp',faanyfile,Fsearchrec);
try
while findresult=0 do
begin
deletefile(extractfilepath('TT.exe')+fsearchrec.name);
findresult:=findnext(fsearchrec);
end;
finally
findclose(fsearchrec);
end;
//============================删除固定目录“c:\temp”下的扩展名为“.tmp”的临时文件.
{ findresult:=findfirst('c:\temp\'+'*.tmp',faanyfile,Fsearchrec);
try
while findresult=0 do
begin
deletefile('c:\temp\'+fsearchrec.name);
findresult:=findnext(fsearchrec);
end;
finally
findclose(fsearchrec);
end;}
//=============================
end;
“*.tmp”可用具体的文件名或其他通配符代换。
别忘了给我加分:)
#4
我给你第一个问题的例子,比如我要搜索d:\下的chenhu2目录,如下:
procedure TForm1.Button1Click(Sender: TObject);
var
SearchRec:TSearchRec;
apppath,ext:string;
begin
listbox1.Items.Clear;
AppPath:='d:\*.*';
ext:='chenhu2';
FindFirst(AppPath,faDirectory,SearchRec);
if SearchRec.Name=ext then
listbox1.Items.Add(SearchRec.Name);
while FindNext(SearchRec)=0 do
if SearchRec.Name=ext then
listbox1.Items.Add(SearchRec.Name);
// listbox1.items为你需要的结果
end;
procedure TForm1.Button1Click(Sender: TObject);
var
SearchRec:TSearchRec;
apppath,ext:string;
begin
listbox1.Items.Clear;
AppPath:='d:\*.*';
ext:='chenhu2';
FindFirst(AppPath,faDirectory,SearchRec);
if SearchRec.Name=ext then
listbox1.Items.Add(SearchRec.Name);
while FindNext(SearchRec)=0 do
if SearchRec.Name=ext then
listbox1.Items.Add(SearchRec.Name);
// listbox1.items为你需要的结果
end;
#5
那要是搜索d盘根目录呢?
#6
需要用递归过程对某个子目录全部遍历
#7
看看这个
http://haitian.myrice.com/Soft/MyPubFuncUnit.Txt
http://haitian.myrice.com/Soft/MyPubFuncUnit.Txt
#8
lhzwxt(lhcz_wxt)方法对