正文

[C]C实现定时删除文件2006-08-25 11:47:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/fengfei/17876.html

分享到:

#include "stdio.h"
#include "string.h"
#include "time.h"
#include "stdlib.h"

int main( void )
{
 char *strTime;
 time_t myTime; // long型时间
 bool isDel;

 time( &myTime );   // 取得时间
 strTime = ctime( &myTime ); // 转换为字符串
 printf( "%s", strTime ); // 显示时间
 
isDel = false;

while( !isDel )    // 程序一直运行,直到删除了文件才结束次程序。
{
          /* 如果为18:00点则删除文件 */
          if ( ( strTime[11] == '1' ) && ( strTime[12] == '8' ) && ( strTime[14] == '0' ) && ( strTime[15] == '0' ) )
          {
                  system( "type aaa.txt" ); // 显示文件的内容
                  system( "del aaa.txt" );    // 删除文件
           }
 }
 system( "pause" ); 

 return 0;
}

如果想要次程序在每次启动计算机后自动执行,则只要HKLM的Run里添加一个字符串键值就可以了。 键值为:删除文件的程序的路径。 假如次程序保存名为TimingDel.exe,则将键值设置为:E:\App Exap\C C++\TimingDel\Debug\TimingDel.exe (这是我的电脑上的路径)。 这样每次启动计算机后他会自动执行。。

阅读(6881) | 评论(6)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

loading...
您需要登录后才能评论,请 登录 或者 注册