|
この様な問題が解けず、悩んでいます。
≪指定したフォルダの中にあるファイルをリスト化するプログラムの作成
リスト項目は「ファイル名」「ファイルの種類」「ファイルの容量」の3つで、各項目ごとに並べ替えが可能とする事≫
挑戦してみて、「ファイル名」「ファイルの種類」「ファイルの容量」をリスト化することはなんとか形にしましたが、各項目ごとに並びかえるという事自体がどうやればいいのかどうしても分かりません。
できればご助言などをいただきたくて、投稿します。
どうかよろしくお願いします
これが自分が組んだソースです 検証していただければ嬉しいです
#include<sys/types.h>
#include<sys/stat.h>
#include<stdio.h>
#include<errno.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>
#include<stdio.h>
#include<dirent.h>
void main(argc,argv)
int argc;
char *argv[];
{
DIR *dir;
struct dirent *dp;
struct stat filestat;
char path[1000];
if(argc<=1){
strcpy(path,".");
}
else{
strcpy(path,argv[1]);
}
if((dir=opendir(path))==NULL){
perror("opendir");
exit(-1);
}
for(dp=readdir(dir);dp!=NULL;dp=readdir(dir)){
stat(dp, &filestat);
printf("--------------------------------------------\n");
printf("%s\n",dp->d_name);
printf("Size: %ld\n",(long)filestat.st_size);
printf("Last accessed: %s", ctime(&filestat.st_atime));
printf("Last modified: %s", ctime(&filestat.st_mtime));
printf("--------------------------------------------\n\n");
}
closedir(dir);
}
|