QFileInfo gives incorrect information
-
I am trying to use QFileInfo class object to get information about file(like when file was created). It is becasue in my app. I have to remove file every 48 hours. I am trying this code on windows Xp. Psudo code is as below.
QFileInfo fl;
QDateTime d = fl.created();
int i = d.daysTo(QDateTime::currentDateTime ());
qDebug("\nDays: %d\n",i);
if(i >= 2){ /// Remove file
.........
}Output:
Days: 126It always gives me 126 days output nomatter on which date I created file.
Any ideas.....
Thanks in advance. -
do you overwrite the same file every time (same file name)? If so i think just the modified date changes but not the created date.
-
Yes you are right. But when I removed that file it just changed modified, accessed date and time. I tried both QFile::remove() and QDir::remove("filename.txt"). Actual code is as below.
QFileInfo fl;
QDateTime d = fl.created();
int i = d.daysTo(QDateTime::currentDateTime ());
qDebug(ā\nDays: %d\nā,i);
if(i >= 2){ /// Remove file
QFile fl("filename.txt"); or QDir d;
fl.remove(); or d.remove("filename.txt");
}QFile file("filename.txt");
QTextStream ou(&file);
file.open(QFlag(0x0004));// append mode
ou<< "..... New File.......";
file.close();How should I remove file so that it has correct information.