
如何用C语言显示指定文件信息?包括创建时间,文件大小.和模糊查找文件?像Windows的搜索一样.还是那个程序.
1个回答
展开全部
#include <stdio.h>
#include <time.h>
#include <io.h>
#include <sys/stat.h>
int main(int argc, char *argv[])
{
FILE *fp;
struct stat statbuf;
struct ftime ft;
if ((fp = fopen(argv[0],"rb"))!= NULL)
{
fstat(fileno(fp), &statbuf);
/* display the information returned */
if (statbuf.st_mode & S_IFCHR)
printf("Handle refers to a device.\n");
if (statbuf.st_mode & S_IFREG)
printf("Handle refers to an ordinary file.\n");
if (statbuf.st_mode & S_IREAD)
printf("User has read permission on file.\n");
if (statbuf.st_mode & S_IWRITE)
printf("User has write permission on file.\n");
printf("Drive letter of file: %c\n", 'A'+statbuf.st_dev);
printf("Size of file in bytes: %ld\n", statbuf.st_size);
printf("Time file last opened: %s\n", ctime(&statbuf.st_ctime));
getftime(fileno(fp), &ft);
printf("File time: %u:%u:%u\n", ft.ft_hour, ft.ft_min, ft.ft_tsec * 2);
printf("File date: %u/%u/%u\n", ft.ft_month, ft.ft_day, ft.ft_year+1980);
fclose(fp);
}
return 0;
}
#include <time.h>
#include <io.h>
#include <sys/stat.h>
int main(int argc, char *argv[])
{
FILE *fp;
struct stat statbuf;
struct ftime ft;
if ((fp = fopen(argv[0],"rb"))!= NULL)
{
fstat(fileno(fp), &statbuf);
/* display the information returned */
if (statbuf.st_mode & S_IFCHR)
printf("Handle refers to a device.\n");
if (statbuf.st_mode & S_IFREG)
printf("Handle refers to an ordinary file.\n");
if (statbuf.st_mode & S_IREAD)
printf("User has read permission on file.\n");
if (statbuf.st_mode & S_IWRITE)
printf("User has write permission on file.\n");
printf("Drive letter of file: %c\n", 'A'+statbuf.st_dev);
printf("Size of file in bytes: %ld\n", statbuf.st_size);
printf("Time file last opened: %s\n", ctime(&statbuf.st_ctime));
getftime(fileno(fp), &ft);
printf("File time: %u:%u:%u\n", ft.ft_hour, ft.ft_min, ft.ft_tsec * 2);
printf("File date: %u/%u/%u\n", ft.ft_month, ft.ft_day, ft.ft_year+1980);
fclose(fp);
}
return 0;
}
来自:求助得到的回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询