views:

381

answers:

4

when i am including (#include in visual studio 2005) this headerfile it is showing the error as (fatal error C1083: Cannot open include file: 'dirent.h': No such file or directory) i am new to C++ can anyone please provide me the solution for this error?

A: 

The error message says it all. The file does not exist or it is not in the correct directory. Check out this website. It includes a free implementation of dirent.h.

hanno
ya! its working thanx for providing me the site.
SHIVA KUMAR
So, how about closing this question?
hanno
Questions don't get close unless they're not real questions for some reason. They should get an accepted answer though, @SHIVA.
Bill
A: 

Try including just dir.h and if that doesn't work try io.h

#include <errno.h>
#include <iostream>
#include <io.h>
#include <time.h>
using namespace std;

bool canDelete(int timeCreate);

int main() {
    struct _finddata_t data;
    int handle;
    handle = _findfirst("test.txt", &data);

    if(handle == -1) {
        exit(1);
    }

    if(canDelete(data.time_create)) {
        cout << "Deleting file ...\n\n";
    } else {
        cout << "File ok.\n\n";
    }
}
/**
* @param: the time in seconds that the file was created.
* @return: true if the file was created more than 7 days, 
* false otherwise.
**/
bool canDelete(int time_create) {
    time_t seconds = time(NULL);
    int days = 7;
    int max_time = 60 * 60 * 24 * days;
    int time_passed = seconds - time_create;
    if(time_passed > max_time) {
        return true;
    } else {
        return false;
    }
}
Pentium10
+1  A: 

You should add the directory where the file is located to the "additional include folders" in the Visual Studio project properties.

Paolo Tedesco
+1  A: 

The file dirent.h is not a C++ Standard header file. As you are on Windows, you probably want to use the FindFirstFile and related functions, declared in windows.h

anon
He said in another thread that he wanted to keep multiplatform.
Manuel
@Manuel In general, it's a good idea to address the question posed in a particular thread.
anon