国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > C++ > 正文

c++ Windows下超時(shí)文件刪除

2019-11-06 07:46:26
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

操作步驟

取得某個(gè)目錄下面所有文件

取得文件的創(chuàng)建日期

取得當(dāng)前日期跟其創(chuàng)建的日期差

刪除文件

獲取文件的創(chuàng)建時(shí)間

int iresult; struct _stat buf; iresult = _stat("D://test.txt", &buf); 獲取當(dāng)前時(shí)間 __time64_t* mptr_currentSeconds = new __time64_t; time(mptr_currentSeconds); printf("current seconds from 1970 :%d/n", *mptr_currentSeconds); m_localTime = localtime(mptr_currentSeconds); printf("current Local time : %d:%d:%d/n", m_localTime->tm_hour, m_localTime->tm_min, m_localTime->tm_sec);

獲取文件列表下所有文件

void getFiles(string path,__time64_t currentTime){ //文件句柄 long hFile = 0; //文件信息 struct _finddata_t fileinfo; string p; if ((hFile = _findfirst(p.assign(path).append("http://*").c_str(), &fileinfo)) != -1) { do { //如果是目錄,迭代之 //如果不是,加入列表 if ((fileinfo.attrib & _A_SUBDIR)) { if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0) getFiles(p.assign(path).append("http://").append(fileinfo.name),currentTime); } else { int iresult; struct _stat buf; iresult = _stat(p.assign(path).append("http://").append(fileinfo.name).c_str(), &buf); cout << "currentTime" << currentTime << " " << fileinfo.name << " " << buf.st_mtime << endl;//打印文件的修改時(shí)間 if ((currentTime-buf.st_atime)>12000) { //這里可以對(duì)超時(shí)文件進(jìn)行操作 } } } while (_findnext(hFile, &fileinfo) == 0); _findclose(hFile); }}

時(shí)間結(jié)構(gòu)體與函數(shù)參考

//<sys/stat.h> struct stat { dev_t st_dev; /* device inode resides on */ ino_t st_ino; /* inode's number */ mode_t st_mode; /* inode's mode */ nlink_t st_nlink; /* number of hard links to the file */ uid_t st_uid; /* user ID of owner */ gid_t st_gid; /* group ID of owner */ dev_t st_rdev; /* device type, for special file inode */ struct timespec st_atimespec; /* time of last
access */ struct timespec st_mtimespec; /* time of last data modification */ struct timespec st_ctimespec; /* time of last file status change */ off_t st_size; /* file size, in bytes */ int64_t st_blocks; /* blocks allocated for file */ u_int32_t st_blksize;/* optimal file sys I/O ops blocksize */ u_int32_t st_flags; /* user defined flags for file */ u_int32_t st_gen; /* file generation number */ };

時(shí)間的轉(zhuǎn)換

struct tm { int tm_sec; /*秒,0-59*/ int tm_min; /*分,0-59*/ int tm_hour; /*時(shí),0-23*/ int tm_mday; /*天數(shù),1-31*/ int tm_mon; /*月數(shù),0-11*/ int tm_year; /*自1900的年數(shù)*/ int tm_wday; /*自星期日的天數(shù)0-6*/ int tm_yday; /*自1月1日起的天數(shù),0-365*/ int tm_isdst; /*是否采用夏時(shí)制,采用為正數(shù)*/ }

日期貯存結(jié)構(gòu)date

struct date { int da_year; /*自1900的年數(shù)*/ char da_day; /*天數(shù)*/ char da_mon; /*月數(shù) 1=Jan*/ }

時(shí)間貯存結(jié)構(gòu)time

struct time { unsigned char ti_min; /*分鐘*/ unsigned char ti_hour; /*小時(shí)*/ unsigned char ti_hund; unsigned char ti_sec; /*秒*/ }char *ctime(long *clock)本函數(shù)把clock所指的時(shí)間(如由函time返回的時(shí)間)轉(zhuǎn)換成數(shù)下列格式的字符串:Mon Nov 21 11:31:54 1983nchar asctime(struct tm *tm)本函數(shù)把指定的tm結(jié)構(gòu)類的時(shí)間轉(zhuǎn)換成下列格式的字符串:Mon Nov 21 11:31:54 1983ndouble difftime(time_t time2,time_t time1)計(jì)算結(jié)構(gòu)time2和time1之間的時(shí)間差距(以秒為單位)struct tm *gmtime(long *clock)本函數(shù)把clock所指的時(shí)間(如由函數(shù)time返回的時(shí)間)轉(zhuǎn)換成格林威治時(shí)間,并以tm結(jié)構(gòu)形式返回struct tm *localtime(long *clock)本函數(shù)把clock所指的時(shí)間(如函數(shù)time返回的時(shí)間)轉(zhuǎn)換成當(dāng)?shù)貥?biāo)準(zhǔn)時(shí)間,并以tm結(jié)構(gòu)形式返回void tzset()本函數(shù)提供了對(duì)UNIX操作系統(tǒng)的兼容性long dostounix(struct date *dateptr,struct time *timeptr)本函數(shù)將dateptr所指的日期,timeptr所指的時(shí)間轉(zhuǎn)換成UNIX格式, 并返回自格林威治時(shí)間1970年1月1日凌晨起到現(xiàn)在的秒數(shù)void unixtodos(long utime,struct date *dateptr,struct time *timeptr)本函數(shù)將自格林威治時(shí)間1970年1月1日凌晨起到現(xiàn)在的秒數(shù)utime轉(zhuǎn)換成DOS格式并保存于用戶所指的結(jié)構(gòu)dateptr和timeptr中void getdate(struct date *dateblk)本函數(shù)將計(jì)算機(jī)內(nèi)的日期寫(xiě)入結(jié)構(gòu)dateblk中以供用戶使用void setdate(struct date *dateblk)本函數(shù)將計(jì)算機(jī)內(nèi)的日期改成由結(jié)構(gòu)dateblk所指定的日期void gettime(struct time *timep)本函數(shù)將計(jì)算機(jī)內(nèi)的時(shí)間寫(xiě)入結(jié)構(gòu)timep中, 以供用戶使用void settime(struct time *timep)本函數(shù)將計(jì)算機(jī)內(nèi)的時(shí)間改為由結(jié)構(gòu)timep所指的時(shí)間long time(long *tloc)本函數(shù)給出自格林威治時(shí)間1970年1月1日凌晨至現(xiàn)在所經(jīng)過(guò)的秒數(shù),并將該值存于tloc所指的單元中. int stime(long *tp)本函數(shù)將tp所指的時(shí)間(例如由time所返回的時(shí)間)寫(xiě)入計(jì)算機(jī)中.

參考網(wǎng)址


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 广元市| 扎囊县| 卢龙县| 大关县| 昌乐县| 汾阳市| 邵东县| 南澳县| 怀仁县| 彭水| 汪清县| 聂拉木县| 南汇区| 玉林市| 尉犁县| 保德县| 无极县| 手游| 二连浩特市| 抚州市| 佛教| 错那县| 平顶山市| 肥西县| 乌兰县| 高州市| 泾川县| 冕宁县| 徐水县| 威信县| 都兰县| 尼木县| 平阳县| 綦江县| 九寨沟县| 平和县| 金昌市| 敖汉旗| 普兰县| 佛教| 庆阳市|