Here's the code I have right now
/* Rename existing project files to .old */
if (FileIOUtil::fileExists(dest, outFileName))
{
QFile oldFile(outFileName);
QFileInfo fileInfo; fileInfo.setFile(oldFile);
QDateTime created = fileInfo.lastModified();
FileIOUtil::mvFile(dest, outFileName,
dest, outFileName + ".old" + created.toString());
}
Note: mvfile
works like the unix command mv
. It just moves a file to a new name.
However, this renames my project.c
to project.c.old.Thu Jan 1 01:00:00 1970
. I'm pretty sure the files I'm trying to rename aren't that old ;)
Any ideas why I'm getting the epoch as a result?
I had to modify the following line:
QFile oldFile(outFileName);
to
QFile oldFile(dest + outFileName);
Or as @Riateche mentioned in his comment, remove oldFile and fileInfo variables completely and do:
QFileInfo(dest+outFileName).created();