Windows PC のフォルダーをスキャンする関数を作成しようとしていますが、そのたびに「Filter.txt」というファイルに「Test Script」という文字列が追加されます。
fopen
問題は 2 です。1 つ目は、ディレクトリ c:\LOG またはそのサブディレクトリでスキャンを実行する必要があることです。2 つ目は、ディレクトリとファイル名を連鎖させる方法がわからないことです。
int main(){
DIR *dir;
FILE * pFile;
char myString[100];
struct dirent *ent;
dir = opendir ("c:\\LOG");
if (dir != NULL) {
/* print all the files and directories */
while ((ent = readdir (dir)) != NULL) {
pFile = fopen ("Filter.txt","a");
if (pFile==NULL)
perror("Error");
else
fprintf(pFile,"%s\n","Test scriptIno");
fclose(pFile);
//printf ("%s\n", ent->d_name);
}
closedir (dir);
} else {
/* Can not open directory */
perror ("");
return EXIT_FAILURE;
}
}