2017-05-23 13 views
1

ディレクトリの存在を確認したいと思います。ディレクトリが存在しない場合でも私はちょうど "はい"と言います。私は何をすべきか?どうもありがとうございました!OPENDIR関数はどのように使うべきですか?

int main() 
{ 
if(opendir("dsfdsgfdsgrs") == NULL) 
    printf("%s","no"); 
else 
    printf("%s","yes"); 

return 0; 
} 
+0

https://stackoverflow.com/questions/9314586/c-faster-way-to-check-if-a-directory-existsあなたが保存する必要があります –

+0

'opendir'の結果を変数に代入して' closedir'を呼び出すことができます –

+2

あなたのコードをコピーして貼り付けてくれます。 – jiveturkey

答えて

1

この例では動作します

#include <stdio.h> 
#include <dirent.h> 

int main(int argc, char ** argv) 
{ 
    DIR *dir; 

    dir = opendir("folder"); 
    if (dir == NULL) { 
     printf("Couldn't open dir\n"); 
    } else { 
     printf("Opened dir\n"); 
    } 

    if (dir != NULL) 
     closedir(dir); 
} 
関連する問題