RT
NULL在TC 2.0中是没有定义的
/*文件操作函数件*/
#include <dir.h>
#include <alloc.h>
#include <stdlib.h>
#include <stdio.h>
struct fileData{
char ff_reserved[21];
char ff_attrib;
unsigned ff_ftime;
unsigned ff_fdate;
long ff_fsize;
char ff_name[13];
struct fileData *nextFile;
};
struct ffblk tempBlk;
struct fileData firstFileData;
struct fileData *currentFileData;
struct fileData *tempFileData;
int fileOperInit();
int fileList(char *path,struct fileData *firstFileData);
/*搜索指定文件目录下所有文件的信息,并存入一个以firstFileData为头的链表*/
int fileOrder(int mode,struct fileData *firstFileData);
/*对一个以firstFileData为头的链表使用MODE模式进行排序
MODE 0:以文件名
1:以最近更新日期
2:以文件大小
3:以文件类型*/
int fileOperInit(){
firstFileData.nextFile = 0;
return 0;
}
int fileList(char *path,struct fileData *firstFileData){
int done;
if (firstFileData.nextFile != 0){
currentFileData = firstFileData->nextFile;
while(currentFileData->nextFile != 0){
tempFileData = currentFileData;
currentFileData = currentFileData->nextFile;
free(tempFileData);
}
free(currentFileData);
firstFileData.nextFile = 0;
}
else{
if ((done = findfirst("*.*",&tempBlk,0)) == 0){
firstFileData.ff_reserved[] = tempBlk.ff_reserved[];
firstFileData.ff_attrib = ff_attrib;
firstFileData.ff_ftime = tempBlk.ff_ftime;
firstFileData.ff_fdate = tempBlk.ff_fdate;
firstFileData.ff_fsize = tempBlk.ff_fsize;
firstFileData.ff_name[] = tempBlk.ff_name[];
}
if (done = findnext(&tempBlk) == 0){
firstFileData.nextFile = (fileData *)malloc(sizeof fileData);
currentFileData = firstFileData.nextFile;
currentFileData.ff_reserved[] = tempBlk.ff_reserved[];
currentFileData.ff_attrib = ff_attrib;
currentFileData.ff_ftime = tempBlk.ff_ftime;
currentFileData.ff_fdate = tempBlk.ff_fdate;
currentFileData.ff_fsize = tempBlk.ff_fsize;
currentFileData.ff_name[] = tempBlk.ff_name[];
}
while (done = findnext(&tempBlk) != 0){
currentFileData.nextFile = (fileData *)malloc(sizeof fileData);
currentFileData = currentFileData.nextFile;
currentFileData.ff_reserved[] = tempBlk.ff_reserved[];
currentFileData.ff_attrib = ff_attrib;
currentFileData.ff_ftime = tempBlk.ff_ftime;
currentFileData.ff_fdate = tempBlk.ff_fdate;
currentFileData.ff_fsize = tempBlk.ff_fsize;
currentFileData.ff_name[] = tempBlk.ff_name[];
}
currentFileData.next = 0;
}
return 0;
}
int fileOrder(int mode,struct fileData *firstFileData){
return 0;
}
int main()
{
fileOperInit();
fileList("D:\\C\\Reader",firstFileData);
printf("%s%s",firstFileData.ff_name[],firstFileData->nextFile->ff_name[]);
getch();
}