intente incluir solo dir.h
y si eso no funciona, intente 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;
}
}
Respondí esto en otra pregunta del mismo usuario: http://stackoverflow.com/questions/2228405/list- the-files-in-particular-folder-in-c-closed. Esta pregunta debe ser cerrada. – Manuel
Manuel: esa no parece la misma pregunta, y está cerrada de todos modos. –
No veo que su respuesta abordara esto directamente. –