|
#include <cstdio>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <ctime>
#include <iostream>
using namespace std;
const int SIZE=1024;
int main()
{
char pwd[SIZE];
getcwd(pwd,SIZE);
DIR* dir=opendir(pwd);
if(dir==NULL)
{
cout<<"Opendir "<<pwd<<" error"<<endl;
exit(0);
}
struct dirent *direntp;
while((direntp=readdir(dir))!=NULL)
{
struct stat statbuf;
stat(direntp->d_name,&statbuf);
cout<<statbuf.st_mode<<" "<<statbuf.st_nlink<<" "<<statbuf.st_uid<<" "
<<statbuf.st_gid<<" "<<statbuf.st_size<<" "<<ctime(&statbuf.st_ctime)
<<" "<<direntp->d_name<<endl;
}
return 0;
}
得到的输出结果格式是这样的:
33188 1 0 0 1146 Sun May 13 22:56:21 2007
mv.cpp
我想要的是这样的:
-rw-r--r-- 1 root root 1146 05-13 22:56 mv.cpp
我是新手,不知道有没有什么系统函数可以把结果转换成我想要的。
thanks a million! |
|