文件的时间属性--〉在线等ing
ishe 2003-09-02 09:35:47 我编程序要得到文件的属性,只有时间属性不知道该怎么办。
我是想,记录该属性到一个链表中(链表我已经做好,就差得到这个属性),
还要写到一个文件中。
我已经用
printf( " %-12s %.24s %9ld\n",
gettogether_file.name, ctime( &( gettogether_file.time_write ) ), gettogether_file.size );
printf("\n\n");
已经可以从屏幕输出,其中gettogether_file是我定义的 结构体(如下)
struct _finddata_t gettogether_file;
全部程序如下:(其中把链表信息写入文件部分,还没有实现)
#include <stdio.h>
#include <iostream.h>
#include <io.h>
#include <process.h>
#include <wchar.h>
#include <time.h>
#include <malloc.h>
#include <string.h>
typedef struct F_Information
{
//char FiIn_reserved[2];/*DOS保留*/
char FiIn_attrib; /*查找到的属性*/
long FiIn_ftime; /*文件时间*/
int FiIn_fdate; /*文件日期*/
long FiIn_fsize; /*文件大小*/
char FiIn_name[13]; /*文件名要足够长*/
struct F_Information *next;
/////maybe others to be added////
}F_Information,*FileInformation;
void main()
{ struct _finddata_t gettogether_file;
long hFile;
char fname[10];
int n,i;
int sys;//属性
int rdo;
int hid;
int arc;
FILE *fp;
if((fp=fopen("newfile","a"))==NULL)//向此文件中写入
{
printf("cannot open outfile");
exit(0);
}
F_Information *L,*p,*h;
L=(FileInformation)malloc(sizeof(F_Information));
L->next=NULL; //先建立一个带表头结点的单链表
printf("Enter the the number of the files\n");
scanf("%d",&n);
printf("Enter the files' names\n\n");
for(i=0;i<n;i++)
{
scanf("%s",&fname);
/* Find first file in current directory */
if( (hFile = _findfirst( fname, &gettogether_file )) == -1L )
printf( "Cann't find the No. %d files in current directory!\n",i+1);
else
{
printf( "Listing of files to be got together\n\n" );
printf( "\nRDO HID SYS ARC FILE DATE %25c SIZE\n", ' ' );
printf( "--- --- --- --- ---- ---- %25c ----\n", ' ' );
printf( ( gettogether_file.attrib & _A_RDONLY ) ? " Y " : " N " );//与运算,取出某一位!!
printf( ( gettogether_file.attrib & _A_SYSTEM ) ? " Y " : " N " );
printf( ( gettogether_file.attrib & _A_HIDDEN ) ? " Y " : " N " );
printf( ( gettogether_file.attrib & _A_ARCH ) ? " Y " : " N " );
printf( " %-12s %.24s %9ld\n",
gettogether_file.name, ctime( &( gettogether_file.time_write ) ), gettogether_file.size );
printf("\n\n");
fprintf(" %-12s %.24s %9ld\n",
gettogether_file.name, ctime( &( gettogether_file.time_write ) ), gettogether_file.size);
p=(FileInformation)malloc(sizeof(F_Information)); //生成新结点
/////////////////////////////下面写入信息!!!!!!!
strcpy(p->FiIn_name,gettogether_file.name);
p->FiIn_fsize=gettogether_file.size;
p->FiIn_ftime=gettogether_file.time_write; //???????????????????????????
//strcpy(p->FiIn_ftime,gettogether_file.time);//???????????????????????????????
p->FiIn_attrib=gettogether_file.attrib;
//////may be others to be added///////
p->next=L->next;L->next=p; //插入到表头
_findclose( hFile );
}
}
h=L;//以下验证我的链表
h=h->next;
cout<<endl<<endl<<endl<<"LinkList Information";
for(i=0;i<n;i++)
{
cout<<endl<<endl;
cout<<"name "<<h->FiIn_name<<endl<<endl;
//cout<<"name "<<fname<<endl<<endl;
cout<<"size "<<h->FiIn_fsize<<endl<<endl;
cout<<"time "<<h->FiIn_ftime<<endl<<endl;
cout<<"attrib "<<h->FiIn_attrib<<endl<<endl;
/////////////may be others to be added/////////////////
sys=((h->FiIn_attrib & _A_SYSTEM) ? 1 : 0);
rdo=((h->FiIn_attrib & _A_RDONLY) ? 1 : 0);
hid=((h->FiIn_attrib & _A_HIDDEN) ? 1 : 0);
arc=((h->FiIn_attrib & _A_ARCH) ? 1 : 0);
/*if(sys)*/ cout<<"sys"<<sys<<endl<<endl;
/*if(rdo)*/ cout<<"rdo"<<rdo<<endl<<endl;
/*if(hid)*/ cout<<"hid"<<hid<<endl<<endl;
/*if(arc)*/ cout<<"arc"<<arc<<endl<<endl;
h=h->next;
}
}