troubleshooting Question

how to check if file is directory or file

Avatar of databoks
databoksFlag for Denmark asked on
Programming Languages-OtherCC++
16 Comments1 Solution1198 ViewsLast Modified:
hi. How can i check if the file is a directory or a file?

I currently have this code:

#include <cstdlib>
#include <MD5.h>
#include <iostream>
#include <istream>
#include <string.h>
#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>
#include <errno.h>
#include <vector>
#include <exception>

using namespace std;
vector<string> myStrings;

MD5 Md5;
int getdir(char* dirname, vector<string>& files);

int main(int argc, char** argv) {

    // puts(Md5.digestFile("D:\\Operating System\\SW_DVD5_Win_Pro_7SP1_32BIT_Danish_X17-24276.img"));

    try {
        char* dirName = "D:\\";
        getdir(dirName, myStrings);
        char *digest;
        //        for(unsigned int i = 0; i < myStrings.size(); i++)
        //        {
        //            char* filename = (char*)myStrings[i].c_str();
        //            puts(filename);
        //        }

    }    catch (exception ex) {
        throw ex.what();


    return 0;
int getdir(char* dirname, vector<string> &files) {
    DIR *dir;
    struct dirent *ent;
    dir = opendir(dirname);
    if (dir != NULL)
                while ((ent = readdir(dir)) != NULL) {
                    char *dirname2 = (char*) dir->dd_name;

                    string FullDirNm = (string)dir->dd_name;
                    FullDirNm = FullDirNm.substr(0, 3);
                    FullDirNm += (string)ent->d_name;
                    // files.push_back(string(ent->d_name));

    return 0;
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 16 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 16 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros