|
はじめまして。
指定したディレクトリ以下全てのファイルを、
(サブディレクトリ内のファイルも含む)
全て標準出力するにはどうしたらいいでしょうか。
指定したディレクトリのみの全ファイル標準出力は
以下のように作成しました。
ぜひご教授をお願いします。
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <sys/stat.h>
int main(int argc,char *argv[])
{
DIR *dir;
struct dirent *dp;
struct stat fi;
char path[512];
if(argc<=1)
strcpy(path,''.'');
else
strcpy(path,argv[1]); /* argv[1]文字列をpathにコピー*/
if((dir=opendir(path))==NULL) /* 見たいディレトリ名を渡す */
{ /* 成功ならばDIR型のポインタ */
perror(``opendir''); /* 失敗すればNULL */
exit(-1);
}
while((dp=readdir(dir)) != NULL) {
stat(dp->d_name,&fi);
if (!(S_ISDIR(fi.st_mode))) printf(``%s\n'',dp->d_name);
}
closedir(dir);
}
|