- #include<sys/stat.h>
-
-
#include<iostream>
-
-
#include<ctime>
-
-
using namespace std;
-
-
-
-
int main()
-
-
{
-
-
struct stat buf;
-
-
int result;
-
-
result=stat("1.mp3",&buf);//stat()函数获取文件状态,成功返回0,失败返回-1。
-
-
if(result!=0)
-
-
perror("Failed !");
-
-
else
-
-
{
-
-
cout<<"size of the file in bytes:"<<"\t"<<buf.st_size<<endl;
-
-
cout<<"time of creation of the file"<<"\t"<<ctime(&buf.st_ctime)<<endl;
-
-
cout<<"time of last modification of the file:"<<"\t"<<ctime(&buf.st_mtime)<<endl;
-
-
cout<<"time of last access of the file:"<<"\t"<<ctime(&buf.st_atime)<<endl;
-
-
}
-
-
getchar();
-
-
return 0;
-
-
}
OUTPUT:
size of the file in bytes: 6083826
time of creation of the file Mon Dec 20 15:44:58 2010
time of last modification of the file: Sun Dec 19 20:37:57 2010
time of last access of the file: Mon Dec 20 15:44:58 2010
文件属性:
(该文件夹中不存在2.MP3,所以:
- #include<sys/stat.h>
-
-
#include<iostream>
-
-
#include<ctime>
-
-
-
-
-
-
using namespace std;
-
-
-
-
int main()
-
-
{
-
-
struct stat buf;
-
-
int result;
-
-
result=stat("2.mp3",&buf);//stat()函数获取文件状态,成功返回0,失败返回-1。
-
-
if(result!=0)
-
-
perror("Failed !");
-
-
else
-
-
{
-
-
cout<<"size of the file in bytes:"<<"\t"<<buf.st_size<<endl;
-
-
cout<<"time of creation of the file"<<"\t"<<ctime(&buf.st_ctime)<<endl;
-
-
cout<<"time of last modification of the file:"<<"\t"<<ctime(&buf.st_mtime)<<endl;
-
-
cout<<"time of last access of the file:"<<"\t"<<ctime(&buf.st_atime)<<endl;
-
-
}
-
-
getchar();
-
-
return 0;
-
-
}
output:
Failed !: No such file or directory
)
阅读(786) | 评论(0) | 转发(0) |