Directory date time
-
not thru Qt, but directories are themselves files, so it is possible.
-
@mrdebug
Speaking for Linux. You can indirectly modify a directory time by adding or deleting (or renaming?) a file/sub-directory inside it. I don't have access to Linux atm, but I believetouch [-t ...]
will alter a directory's timestamp.So the
utime(2)
system call must work on directories and be callable from your C++ code. I don't know whether Qt provides an interface for this (perhaps not).For Windows I don't know what's available.
-
on Windows
attrib -r +s +h "C:\path\to\directory" and then
forfiles /p "C:\path\to\directory" /s /m * /c "cmd /c echo @fdate @ftime @path"on LInux
touch -d "YYYY-MM-DD HH:MM:SS" /path/to/directory or
touch -t "YYYY-MM-DD HH:MM:SS" /path/to/directory -
Hi, in order to edit the date time of a directory there isn't a Qt way up to now.
On unix this is a working approach:
utimbuf times; times.actime= QDTLastAccess.toTime_t(); times.modtime= QDTLastWrite.toTime_t(); bool Result= utime(FileOut.toStdString().c_str(), ×)== 0;
On Windows (the TimetToFileTime() function is taken from MIcrosoft technet):
FILETIME FTCreation; FILETIME FTLastAccess; FILETIME FTLastWrite; TimetToFileTime(QDTCreation.toTime_t(), &FTCreation); TimetToFileTime(QDTLastAccess.toTime_t(), &FTLastAccess); TimetToFileTime(QDTLastWrite.toTime_t(), &FTLastWrite); HANDLE h; h= CreateFileA(FileOut.toStdString().c_str(), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, nullptr); if (h!= INVALID_HANDLE_VALUE) { Result= SetFileTime(h, &FTCreation, &FTLastAccess, &FTLastWrite); CloseHandle(h); }
-
Which is fine for academic curiosity but @JoeCFD mentioned the most straight forward mechanism.
-
Which is fine for academic curiosity but @JoeCFD mentioned the most straight forward mechanism.
@Kent-Dorfman
Except that the OP did not say they just wanted a command-line way to do it, I thought they meant they wanted to be able to do it in code from a Qt program :)