之前練習,linux專用的c++函式,想用來偵測檔案時間來判斷是否須更新設定值,
結果被前輩打槍,說一直使用FILE IO,慢的跟龜一樣,怎可以用來檢查設定值。
當作練習用,留下來給世人嘲笑我的愚蠢用。ε( ̄□ ̄)3||
++++++++++++++++
#include
#include
#include
#include
#include
using namespace std;
void usage()
{
cout cout}
int main(int argc,char* argv[])
{
struct stat sb;
if (argc != 2)
{
usage();
exit(EXIT_FAILURE);
}
if(-1 == stat(argv[1],&sb))
{
cout exit(EXIT_FAILURE);
}
/* if( S_ISREG != sb.st_mode )
{
switch (sb.st_mode & S_IFMT)
{
case S_IFBLK: printf("block device\n"); break;
case S_IFCHR: printf("character device\n"); break;
case S_IFDIR: printf("directory\n"); break;
case S_IFIFO: printf("FIFO/pipe\n"); break;
case S_IFLNK: printf("symlink\n"); break;
case S_IFREG: printf("regular file\n"); break;
case S_IFSOCK: printf("socket\n"); break;
default: printf("unknown?\n"); break;
}
return -1;
}*/
struct tm * timeinfo;
timeinfo = localtime ( &sb.st_mtime );
char szFileTime[128];
strftime (szFileTime,128,"FileTime=[%Y/%m/%d %H:%M:%S]",timeinfo);
cout
return 0;
}
- Mar 23 Fri 2012 15:52
2012/03/23 【C++,Linux系統 抓取 檔案時間】
close
全站熱搜
留言列表
發表留言