类型:转载 责任编辑:asp 日期:2007/03/01
目的:用vc写个程序来遍历一个目录下所有文件,比较文件创建时间与当前系统时间,如果创建时间已经超过七天,那就删除。现在遍历的代码已经写好,就差时间比较这一块了,请大家帮忙呀:)
推荐阅读
首先用getfiletime得到文件的创建时间。
再得到系统时间,
把两个时间相减得出一个ctimespan的变量,
判断ctimespan这个变量的getdays()是否大于7,
以决定是否要删除。
ctime m_tstart;
ctimespan m_tlast;
lpfiletime lpcreationtime;
getfiletime(wfd,ipcreationtime);//wfd为文件句柄
m_tstart=ctime::getcurrenttime();
ctime m_tcreat=ctime(lpcreationtime);
m_tlast=m_tstart-m_tcreat;
m_tlast.getdays();
if ( m_tlast.getdays() > 7 ){
deletefile(szfile);
}