打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
DELPHI编程清理指定文档夹下的过期临时文档
有些时候操作系统会生成很多临时文档,咱们需求帮助清理临时文档的功能。
编程论坛最近有人研讨那个疑难问题,小新就把自个的窍门和大部份人共享一下。
在DELPHI编程中能够利用FindFirst/FindNext参数例遍制定列表的文档,并根据文档名和生成时候来判断也许需求清除。
其中涉及文档生成时候需求从FileData的框架体里ftCreationTime获得,ftCreationTime为_FileTime框架C++声明如下
typedef struct _FILETIME { // ft
DWORD dwLowDateTime;
DWORD dwHighDateTime;
} FILETIME;
此框架需求经过API FileTimeToSystemTime来转换成操作系统时候,声明如下
BOOL FileTimeToSystemTime(
CONST FILETIME *lpFileTime, // pointer to file time to convert
LPSYSTEMTIME lpSystemTime // pointer to structure to receive system time
);
systemtime声明如下
typedef struct _SYSTEMTIME { // st
WORD wYear;
WORD wMonth;
WORD wDayOfWeek;
WORD wDay;
WORD wHour;
WORD wMinute;
WORD wSecond;
WORD wMilliseconds;
} SYSTEMTIME;
那样就能够经过操作系统时候来判断也许是指定日期之前的临时数据了。
程式如下
function ClearTempFile: Boolean;
var
SearchRec: TSearchRec;
systime: TSystemTime;
path: string;
begin
result := false;
path := ExtractFilePath(Application.ExeName) + 'web\chart\';
if not DirectoryExists(path) then
Exit;
if FindFirst(path + '*.gif', faAnyFile, SearchRec) <> 0 then
begin
exit;
end;
repeat
if (SearchRec.Attr and faDirectory) = faDirectory then //判断也许是列表
Continue;
if SearchRec.Name <> 'score.gif' then //假如是指定文档则不删除
begin
FileTimeToSystemTime(SearchRec.FindData.ftCreationTime, systime);
if EncodeDate(systime.wYear, systime.wMonth, systime.wDay) < Date then //也许是一天以前的临时数据
begin
//ShowMessage('因该删除' + SearchRec.Name);
DeleteFile(path + SearchRec.Name);
end;
end;
until FindNext(SearchRec) <> 0; //直到没有文档
FindClose(SearchRec);
result := true;
end;
欢迎大部份人到http://www.programbbs.com沟通研讨。
以上程式在DELPHI编程7下测试经过。
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Excel和Word文档断电后的恢复
word未保存如何恢复
Delphi控制Word编程手记
伪造的再好也能把你挖出来!如何对Word二进制文档进行分析?
Delphi 的 7zip 压缩算法
UTC转换本地时间
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服