Cでこれができるかどうかはわかりませんが、ディレクトリを調べて、ディレクトリのすべての内容を各ファイルのファイルサイズとともに出力するプログラムを作成できることを願っています。私はそれを次のようにしたかったのです(おそらく):
filename.txt -- 300 バイト
filename2.txt -- 400 バイト
filename3.txt -- 500 バイト
等々。
これまでのところ、ファイルを開くことができるプログラムを作成し、バイトを出力しますが、ディレクトリ全体を読み取るわけではなく、読み取りたいファイルを特定する必要があります.. (これは私が欲しいです)。
これが私がこれまでに持っているものです:
#include <stdio.h>
int main(){
FILE *fp; // file pointer
long fileSize;
int size;
// opens specified file and reads
fp = fopen( "importantcommands.txt", "rw" );
if( fp == NULL ){
printf( "Opening file error\n" );
return 0;
}
// uses fileLength function and prints here
size = fileLength(fp);
printf( "\n Size of file: %d bytes", size );
fclose(fp);
return 0;
}
int fileLength( FILE *f ){
int pos;
int end;
// seeks the beginning of the file to the end and counts
// it and returns into variable end
pos = ftell(f);
fseek (f, 0, SEEK_END);
end = ftell(f);
fseek (f, pos, SEEK_SET);
return end;
}
助けてください。