求助,请各位大哥写个函数请教:
假设有文件:c;\ff\aa.db;
c;\ff\bb.db;
c;\ff\cc.db;
c;\ff\dd.db;
c:\ff\aa.xls;
c:\ff\ss.ims;
我的要求是:以 c;\ff 为参数
找出 ff 目录下 所有以 bd 结尾的文件得到
aa.db;
bb.db;
cc.db;
dd.db;然后把
aa.db;
bb.db;
cc.db;
dd.db;
放到 combobox1 的 Items 里
请教各位大哥这种功能怎么实现啊?
谢谢 各位大哥!
假设有文件:c;\ff\aa.db;
c;\ff\bb.db;
c;\ff\cc.db;
c;\ff\dd.db;
c:\ff\aa.xls;
c:\ff\ss.ims;
我的要求是:以 c;\ff 为参数
找出 ff 目录下 所有以 bd 结尾的文件得到
aa.db;
bb.db;
cc.db;
dd.db;然后把
aa.db;
bb.db;
cc.db;
dd.db;
放到 combobox1 的 Items 里
请教各位大哥这种功能怎么实现啊?
谢谢 各位大哥!
解决方案 »
- delphi调用ocx传出参数的问题
- 问一下,这个下拉框的高度,怎么改变啊?着急
- delphi中 如果我的日期垮月了有函数会自动垮月的吗?垮完月就自动垮年!同样的减也可以!然后显示出最后的时期
- 急! fastReport 报表生成后,双击两下,就可以对fastReport所产生的报表进行修改,为什么我做的就不行!?
- 如何在98下对磁盘进行实模式读写?????
- http://expert.csdn.net/Expert/topic/3036/3036638.xml?temp=.8686792
- 【百分相赠】如何让控件的显示能超过主窗口?主窗口的高度可以只有一点点,但控件的高度允许超出窗口下方,如何实现,请给个方案吧,谢谢
- 真的搞不懂是什么原因呀
- 第三方控件的Methods引用问题,好奇怪,我真菜鸟吗?呵呵..
- 获得DC(画布)的大小
- 关于except处理的简单问题
- 有谁知道Win2003/WinXP启动画面的那种进度条那种控件包里有?
-----------
刪除一個文件夾下面所有的子文件夾和所有的文件??急
以下是你的问题解:
uses FileCtrl;procedure DelTree(const Directory: TFileName);
var
DrivesPathsBuff: array[0..1024] of char;
DrivesPaths: string;
len: longword;
ShortPath: array[0..MAX_PATH] of char;
dir: TFileName;
procedure rDelTree(const Directory: TFileName);
var
SearchRec: TSearchRec;
Attributes: LongWord;
ShortName, FullName: TFileName;
pname: pchar;
begin
if FindFirst(Directory + '*', faAnyFile and not faVolumeID,
SearchRec) = 0 then begin
try
repeat // 检测所有的文件和目录
if SearchRec.FindData.cAlternateFileName[0] = #0 then
ShortName := SearchRec.Name
else
ShortName := SearchRec.FindData.cAlternateFileName;
FullName := Directory + ShortName;
if (SearchRec.Attr and faDirectory) <> 0 then begin
// 是一个目录
if (ShortName <> '.') and (ShortName <> '..') then
rDelTree(FullName + '\');
end else begin
// 是一个文件
pname := PChar(FullName);
Attributes := GetFileAttributes(pname);
if Attributes = $FFFFFFFF then
raise EInOutError.Create(SysErrorMessage(GetLastError));
if (Attributes and FILE_ATTRIBUTE_READONLY) <> 0 then
SetFileAttributes(pname, Attributes and not
FILE_ATTRIBUTE_READONLY);
if Windows.DeleteFile(pname) = False then
raise EInOutError.Create(SysErrorMessage(GetLastError));
end;
until FindNext(SearchRec) <> 0;
except
FindClose(SearchRec);
raise;
end;
FindClose(SearchRec);
end;
if Pos(#0 + Directory + #0, DrivesPaths) = 0 then begin
// 如果不是根目录,就删除
pname := PChar(Directory);
Attributes := GetFileAttributes(pname);
if Attributes = $FFFFFFFF then
raise EInOutError.Create(SysErrorMessage(GetLastError));
if (Attributes and FILE_ATTRIBUTE_READONLY) <> 0 then
SetFileAttributes(pname, Attributes and not
FILE_ATTRIBUTE_READONLY);
if Windows.RemoveDirectory(pname) = False then begin
raise EInOutError.Create(SysErrorMessage(GetLastError));
end;
end;
end;
// ----------------
begin
DrivesPathsBuff[0] := #0;
len := GetLogicalDriveStrings(1022, @DrivesPathsBuff[1]);
if len = 0 then
raise EInOutError.Create(SysErrorMessage(GetLastError));
SetString(DrivesPaths, DrivesPathsBuff, len + 1);
DrivesPaths := Uppercase(DrivesPaths);
len := GetShortPathName(PChar(Directory), ShortPath, MAX_PATH);
if len = 0 then
raise EInOutError.Create(SysErrorMessage(GetLastError));
SetString(dir, ShortPath, len);
dir := Uppercase(dir);
rDelTree(IncludeTrailingBackslash(dir));
end;
Sample calls
------------删除 C:\TEMP\A123 目录
DelTree('C:\TEMP\A123');使用方法:DelTree('A:'); // or DelTree('A:\');
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,strutils;type
TForm1 = class(TForm)
Button1: TButton;
ComboBox1: TComboBox;
procedure Button1Click(Sender: TObject);
procedure CreateDirTree(path: string);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
strtmp:string;
implementation{$R *.dfm}
procedure TForm1.CreateDirTree(path: string);
var
SR:TSearchRec;
found:integer;
begin
found:=FindFirst(path+'*.*',faAnyFile,SR);
while found=0 do
begin
strtmp:=LowerCase(sr.Name);
if LeftStr(strtmp,3)='.db' then
begin
ComboBox1.Items.Add(path+sr.Name);
CreateDirTree(path+SR.Name+'\');
end;
found:=FindNext(SR);
end;
FindClose(SR);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
CreateDirTree('C:\ff\');
end;end.
可以了!
procedure TForm1.CreateDirTree(path: string);
var
SR:TSearchRec;
found:integer;
strtmp:string;
begin
ComboBox1.Items.Clear;
found:=FindFirst(path+'*.*',faAnyFile,SR);
while found=0 do
begin
strtmp:=LowerCase(SR.Name);
if Pos('.doc',strtmp)>0 then
begin
ComboBox1.Items.Add(SR.Name);
//CreateDirTree(path+SR.Name);
end;
found:=FindNext(SR);
end;
FindClose(SR);
end;procedure TForm1.Button1Click(Sender: TObject);
begin
CreateDirTree('C:\Documents and Settings\administrator\My Documents\xielaixiang\');
end;
因为在揭贴时,没有看到大哥的留言
实在抱歉!