查找一个指定文件
比如说
abc.txt
这个文件可能在C盘可能在D盘,也有可能在H盘请问,如何找到这个文件?找到这个文件后,返回文件路径,如果找到了,就停止查找,如果没找到就CDEFGH找,如果找完了全部硬盘还是没有找到就返回没找到用户可以在中途停止查找请问,这个findfirst之类的函数要怎么用?
谢谢,另外,中途停止,应该怎么写?
比如说
abc.txt
这个文件可能在C盘可能在D盘,也有可能在H盘请问,如何找到这个文件?找到这个文件后,返回文件路径,如果找到了,就停止查找,如果没找到就CDEFGH找,如果找完了全部硬盘还是没有找到就返回没找到用户可以在中途停止查找请问,这个findfirst之类的函数要怎么用?
谢谢,另外,中途停止,应该怎么写?
解决方案 »
- 在delhpi7中专家模版中追加自定义FORM的问题
- ★★★FireBird/InterBase可以很精彩
- 如何将表中字段的值,赋值给ComboBox?
- 我用了lookup字段,为什么grid里面没出现下拉框那?
- 关于插入数据库记录的麻烦问题!
- 请教一个问题。
- 如何在DELPHI中实现能播放多种文件格式的多媒体程序(如超级解霸2001XP)
- 如何在已知表中创建一个字段?
- 请教一下条形码扫描器的编程问题
- 在delphi中怎么把一个长整型的数设为颜色值?我从其它非delphi控件获得的颜色值是长整型,但delphi的颜色值显然不是用长整型表示,请问这时候我怎样把这个长整型的数作为delphi中控件的背景色。
- 祝贺月亮大喜!
- 连接VFOXPRO的字符串该用那个?来看下我这里奇怪的现象~~~顶者有分~~
--------------------------
//查找所有文件,转自超级猛料.
--------------------------------
procedure findall(disk,path: String; var fileresult: Tstrings);
var
fpath: String;
fs: TsearchRec;
begin
fpath:=disk+path+'\*.*';
if findfirst(fpath,faAnyFile,fs)=0 then
begin
if (fs.Name<>'.')and(fs.Name<>'..') then
if (fs.Attr and faDirectory)=faDirectory then
findall(disk,path+'\'+fs.Name,fileresult)
else
fileresult.add(disk+strpas(strupper(pchar(path)))+'\'+strpas(
strupper(pchar(fs.Name)))+'('+inttostr(fs.Size)+')');
while findnext(fs)=0 do
begin
if (fs.Name<>'.')and(fs.Name<>'..') then
if (fs.Attr and faDirectory)=faDirectory then
findall(disk,path+'\'+fs.Name,fileresult)
else
fileresult.add(disk+strpas(strupper(pchar(path)))+'\'+str
pas(strupper(pchar(fs.Name)))+'('+inttostr(fs.Size)+')');
end;
end;
findclose(fs);
end; procedure DoSearchFile(Path: string; Files: TStrings = nil);
var
Info: TSearchRec; procedure ProcessAFile(FileName: string);
begin
if Assigned(PnlPanel) then
PnlPanel.Caption := FileName;
Label2.Caption := FileName;
end; function IsDir: Boolean;
begin
with Info do
Result := (Name <> '.') and (Name <> '..') and ((attr and fadirectory) = fadirectory);
end; function IsFile: Boolean;
begin
Result := not ((Info.Attr and faDirectory) = faDirectory);
end;begin
Path := IncludeTrailingBackslash(Path);
try
if FindFirst(Path + '*.*', faAnyFile, Info) = 0 then
if IsFile then
ProcessAFile(Path + Info.Name)
else if IsDir then DoSearchFile(Path + Info.Name);
while FindNext(Info) = 0 do
begin
if IsDir then
DoSearchFile(Path + Info.Name)
else if IsFile then
ProcessAFile(Path + Info.Name);
Application.ProcessMessages;
if QuitFlag then Break;
Sleep(100);
end;
finally
FindClose(Info);
end;
end;