读取文件夹下最近三天的文件名 文件按时间产生

#include <windows.h>
#include <stdio.h>
#include<time.h>

void setYearMonth(char *nowDay,char *yesDay,char *befDay){
	char date[15];//yyyymmdd*.dbf
	time_t now;//实例化time_t结构
	struct tm  *timenow;//实例化tm结构指针
	time(&now);
	timenow = localtime(&now);
	sprintf(date,"%4d%02d%02d*.dbf",timenow->tm_year+1900,timenow->tm_mon+1, timenow->tm_mday);
	strcpy(nowDay,date);
	now = now - 86400;
	timenow = localtime(&now);
	sprintf(date,"%4d%02d%02d*.dbf",timenow->tm_year+1900,timenow->tm_mon+1, timenow->tm_mday);
	strcpy(yesDay,date);
	now = now - 86400;
	timenow = localtime(&now);
	sprintf(date,"%4d%02d%02d*.dbf",timenow->tm_year+1900,timenow->tm_mon+1, timenow->tm_mday);
	strcpy(befDay,date);
}
void enum_path(char *cpath,char *cfile){ 
	WIN32_FIND_DATA wfd; 
	HANDLE hfd; 
	char cdir[MAX_PATH]; 
	char subdir[MAX_PATH]; 
	int r; 
	GetCurrentDirectory(MAX_PATH,cdir); 
	SetCurrentDirectory(cpath); 
	hfd = FindFirstFile(cfile,&wfd); 
	if(hfd!=INVALID_HANDLE_VALUE) { 
		do{ 
			printf("%s\n",wfd.cFileName); 
		}while(r=FindNextFile(hfd,&wfd),r!=0); 
	} 
	SetCurrentDirectory(cdir); 
} 
int main(){
	char today[15],yesday[15],befday[15];
	setYearMonth(today,yesday,befday);
	printf("%s\n",today);
	printf("%s\n",yesday);
	printf("%s\n",befday);

	enum_path("D:\\WINGDH\\bg\\num",today);
	enum_path("D:\\WINGDH\\bg\\num",yesday);
	enum_path("D:\\WINGDH\\bg\\num",befday);
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值