development:cpp:folderfile_exist

C++ Check if folder or file exists (linux)

Since everything is a file in linux, the procedure is the same both for folders and files

#include <stdio.h>
#include <iostream>
#include <fstream>
int  main()
{
        if (std::ifstream("/folder")) { //folder
                std::string badge = "/folder/file";
                if (std::ifstream(badge)) {
                        std::cout << "File exists" << std::endl;
                } else {
                        std::cout << "File doesn't exist" << std::endl;
                }
        } else {
                std::cout << "Folder doesn't exist" << std::endl;
        }
 
        return 0;
}
Enter your comment:
J R U N U
 
  • development/cpp/folderfile_exist.txt
  • Last modified: 2019-10-31 09:04
  • (external edit)