Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Directory date time
Qt 6.11 is out! See what's new in the release blog

Directory date time

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 4 Posters 1.1k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • mrdebugM Offline
    mrdebugM Offline
    mrdebug
    wrote on last edited by
    #1

    Hi, is there a way to change a directory (not a file) date time?

    Need programmers to hire?
    www.labcsp.com
    www.denisgottardello.it
    GMT+1
    Skype: mrdebug

    JonBJ 1 Reply Last reply
    0
    • Kent-DorfmanK Offline
      Kent-DorfmanK Offline
      Kent-Dorfman
      wrote on last edited by
      #2

      not thru Qt, but directories are themselves files, so it is possible.

      The dystopian literature that served as a warning in my youth has become an instruction manual in my elder years.

      1 Reply Last reply
      0
      • mrdebugM mrdebug

        Hi, is there a way to change a directory (not a file) date time?

        JonBJ Online
        JonBJ Online
        JonB
        wrote on last edited by
        #3

        @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 believe touch [-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.

        1 Reply Last reply
        0
        • JoeCFDJ Offline
          JoeCFDJ Offline
          JoeCFD
          wrote on last edited by JoeCFD
          #4

          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

          1 Reply Last reply
          1
          • mrdebugM Offline
            mrdebugM Offline
            mrdebug
            wrote on last edited by
            #5

            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(), &times)== 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);
                        }
            

            Need programmers to hire?
            www.labcsp.com
            www.denisgottardello.it
            GMT+1
            Skype: mrdebug

            1 Reply Last reply
            0
            • Kent-DorfmanK Offline
              Kent-DorfmanK Offline
              Kent-Dorfman
              wrote on last edited by
              #6

              Which is fine for academic curiosity but @JoeCFD mentioned the most straight forward mechanism.

              The dystopian literature that served as a warning in my youth has become an instruction manual in my elder years.

              JonBJ 1 Reply Last reply
              0
              • Kent-DorfmanK Kent-Dorfman

                Which is fine for academic curiosity but @JoeCFD mentioned the most straight forward mechanism.

                JonBJ Online
                JonBJ Online
                JonB
                wrote on last edited by
                #7

                @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 :)

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved