我用一个临时文件夹里存放一些excel临时文件在程序结束时想删除这些临时文件如何才能实现呀!
解决方案 »
- 在delphi中如何使用sql脚本文件
- 急急急!!!哪位大哥有获取各种图象的基本信息的代码,主要是高度信息!
- 日期
- ★★★喜得一女,特放分200,欢迎大家捧场★★★
- dephi串口通讯问题,用spcomm控件,接受到错误信息后就不再相应发送命令。
- 用delphi怎样访问Automation (OLE /COM)对象?
- 高手!!快来呀!!!!!!
- 这个问题没人知道吗?如何获取一台win2k机器配置的多个ip地址?
- 100分求:那里有台湾钱达智先生《delphi学习笔记》完整版本下载?
- 临时表的数据更新后如何更新主表问题
- 菜鸟提问:程序打包发布问题(sql server 2000+bde+多层) 使用installshield express
- 关于酒店的夜审及日期问题
lsPath: string;
FileOp: TSHFileOpStruct;
begin
lsPath := 'c:\temp\';
//删除临时文件
with FileOp do begin
Wnd := 0;
wFunc := FO_DELETE;
pFrom := PChar(lsPath + '*.*' + #0); //取目录,与isFaq没有实际关系
pTo := nil;
fFlags := FOF_SILENT + FOF_NOCONFIRMATION ;
fAnyOperationsAborted := False;
hNameMappings := nil;
lpszProgressTitle := nil;
end;
SHFileOperation(FileOp);
RemoveDir(lsPath );
end;
TFileClass = class
private
procedure CleanDirectoryProc(sFileName: string; var bContinue: Boolean);
end;
TEnumDirectoryFileProc = procedure (Filename: string; var bContinue: Boolean) of object;
{===============================================================
功 能: 删除文件或文件夹
参 数: sFileName 文件或文件夹名
返回值:
备 注: 原形
=================================================================}
procedure TFileClass.CleanDirectoryProc(sFileName: string; var bContinue: Boolean);
var
Attr: Integer;
begin
Attr := FileGetAttr(sFileName);
Attr := (not faReadOnly) and Attr; // Turn off ReadOnly attribute
Attr := (not faHidden) and Attr; // Turn off Hidden attribute
FileSetAttr(sFileName, Attr); if Attr and faDirectory <> 0 then
RMDir(sFileName)
else
SysUtils.DeleteFile(sFileName);
end;{=====================================================
功 能: 删除该目录及以下所有文件夹和文件
参 数: sDir 文件夹名称
返回值:
备 注:
======================================================}
procedure FileDeleteDirectory(sDir: string);
begin
//if not MsgYesNoBox('确信要删除该目录及以下所有文件夹和文件吗?') then exit;
with TFileClass.Create do
try
EnumDirectoryFiles(sDir, '*.*', faAnyFile, CleanDirectoryProc);
finally
Free;
end;
RMDir(sDir);
end;{=====================================================
功 能: 删除该目录及以下所有文件夹和文件
参 数: sDir 文件夹名称 SMASK/过滤文件字符串
Attr 文件属性 EnumDirectoryFileProc 本参数为删除过程
返回值:
备 注:
======================================================}
procedure EnumDirectoryFiles(sDir, SMASK: string; Attr: Integer; EnumDirectoryFileProc: TEnumDirectoryFileProc);
var
SearchRec: TSearchRec;
Status : Integer;
bContinue: Boolean;
begin
sDir := PathWithSlash(sDir); // traverse child directories
Status := FindFirst(sDir + '*.*', faDirectory, SearchRec);
try
while Status = 0 do
begin
if (SearchRec.name <> '.') and (SearchRec.name <> '..') then
EnumDirectoryFiles(sDir + SearchRec.name, SMASK, Attr, EnumDirectoryFileProc); Status := FindNext(SearchRec);
end;
finally
SysUtils.FindClose(SearchRec);
end; // exam each valid file and invoke the callback func
Status := FindFirst(sDir + SMASK, faAnyFile, SearchRec);
try
while Status = 0 do
begin
if (SearchRec.Attr and Attr <> 0) and (FileExists(sDir + SearchRec.name) or DirectoryExists(sDir + SearchRec.name)) and
not ((SearchRec.Attr and faDirectory <> 0) and ((SearchRec.name = '.') or (SearchRec.name = '..'))) then
begin
bContinue := True;
EnumDirectoryFileProc(sDir + SearchRec.name, bContinue);
if not bContinue then Break;
end; Status := FindNext(SearchRec);
end; finally
SysUtils.FindClose(SearchRec);
end;
end;
上次回答的...
var
sr:Tsearchrec;
err:integer;
filepath:string;
begin
err:=findfirst('*.*',$3F,sr);
while (err=0) do
begin
if sr.Name[1]<>'.' then
begin
if (sr.Attr and fadirectory)=0 then
begin
deletefile(sr.Name);
end;
if (sr.Attr and fadirectory)=16 then
begin
chdir(sr.name);
filepath:=ExpandFileName(sr.name); maketree;
chdir('..');
end;
end;
err:=findnext(sr);
end;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
chdir(Edit1.text);
maketree;
rmdir('c:\1\1');
end;
var
hFindFile: HWND;
FindFileData: WIN32_FIND_DATA;
sr: TSearchRec;
begin
sDir:= sDir + '\';
hFindFile:= FindFirstFile(pchar(sDir + fExt), FindFileData);
if hFindFile <> NULL then
begin
deletefile(sDir + FindFileData.cFileName);
while FindNextFile(hFindFile, FindFileData) <> FALSE do
deletefile(sDir + FindFileData.cFileName);
end;
sr.FindHandle:= hFindFile;
FindClose(sr);
end;