跨平台查询文件时间,如果超过7天,删除该文件(windows和linxu测试过)
2024-10-18 01:59:42
windows调用的是_stat函数,linux调用的是stat函数。
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <errno.h> int main( void )
{
int result;
char* filename = "putty.exe";
//errno_t err;
#ifdef WIN32
struct _stat buf;
result = _stat( filename, &buf );
#else
struct stat buf;
result = stat(filename, &buf);
#endif if( result != )
{
perror( "Problem getting information" );
switch (errno)
{
case ENOENT:
printf("File %s not found.\n", filename);
break;
case EINVAL:
printf("Invalid parameter to _stat.\n");
break;
default:
/* Should never be reached. */
printf("Unexpected error in _stat.\n");
}
}
else
{
// Output some of the statistics:
printf( "File size : %ld\n", buf.st_size );
printf( "Drive : %c:\n", buf.st_dev + 'A' ); time_t t;
tzset(); /*tzset()*/
t = time(NULL);
if((t - buf.st_mtime) > )//604800是7天的秒数,下面是删除超过7天的文件
{
remove(filename);
printf("remove file : %s \n" ,filename);
} } }
最新文章
- [转]金融业容灾技术分析 (终于看到QREP了)
- iOS开发工程师面试题(二)
- 精品干货丨APP常用导航框架
- 孙鑫MFC学习笔记1.Windows应用程序运行机理
- UVa 10810 - Ultra-QuickSort
- 设置VMWARE通过桥接方式使用主机网卡上网
- uva - 133 The Dole Queue(成环状态下的循环走步方法)
- 上传代码到cocoapod ,自己的框架提供给开发者使用
- PHP学习笔记五【方法】
- SQL点滴14—编辑数据
- ogg 初始化
- Codeforces Good Bye 2016 题解
- C3制作导航栏分割线及立体风格
- javascript的数组之map()
- neo4j通过LOAD CSV导入结点和关系
- Deep Learning中的Large Batch Training相关理论与实践
- linux目录文件及系统启动知识
- 2019.02.14 codechef Chef at the Food Fair(线段树+泰勒展开)
- dup,dup2函数【转】
- Java字节流与字符流