我用TC写了一个,mydir命令程序,只是大概演示了输出信息时上翻滚屏等操作,目前只能列表文件名,没有大小、时间等信息,(加上去并不难),
目前的问题是:
我是采用findfirst() findnext()两个函数来模仿DIR命令的作用的。
但是发现其局限性很大,也许是我的方法不对,还请各位点评一下。
#include
#include
int main(int argc,char*argv)
{
unsigned short p,line,r,i,j,maxrow=20;
struct ffblk *fp;
char** row=(char**)malloc(20*4);
if(!row)
{
printf("out of memory!"

;
exit(1);
}
fp=(struct ffblk*)malloc(sizeof(struct ffblk));
if(!fp)
{
printf("out of memory!"

;
exit(1);
}
for(r=0;r<20;r++)
{
row=(char*)malloc(80);
if(!row)
{
printf("out of memory!"

;
exit(1);
}
for(i=0;iff_name
;i++)row=fp->ff_name;
while(!findnext(fp))
{
if(r++==maxrow-1)
{
j=0;
maxrow+=20;
row=(char**)realloc(row,maxrow*4);
if(!row)
{
printf("out of memory!"
;
exit(1);
}
for(j=0;j<20;j++)
{
row=(char*)malloc(80);
for(i=0;iff_name;i++)row=fp->ff_name;
}
p=maxrow/20;
for(j=0;j<p-1
{
printf("Display page: %d\n",j+1);
for(i=0;i<20;i++)
printf("%s\n",row);
printf("press U to uppage, E to end;other key continue..\n"
;
switch(i=getch())
{
case 'U':
case 'u':
if(j)j--;
break;
case 'E':
case 'e':
j=p-1;break;
default :
j++;
}
}
line=r%20;
printf("Display page: %d\n",j+1);
for(i=0;i<=line;i++)
printf("%s\n",row);
printf("Total %d files in this folder.\n",r+1);
for(j=0;j<maxrow;j++)
free(row);
free(row);
free(fp);
return 0;
}