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

Directory date time

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 4 Posters 669 Views
  • 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.
  • M Offline
    M Offline
    mrdebug
    wrote on 12 Jan 2023, 09:47 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

    J 1 Reply Last reply 12 Jan 2023, 13:07
    0
    • K Offline
      K Offline
      Kent-Dorfman
      wrote on 12 Jan 2023, 09:52 last edited by
      #2

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

      1 Reply Last reply
      0
      • M mrdebug
        12 Jan 2023, 09:47

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

        J Offline
        J Offline
        JonB
        wrote on 12 Jan 2023, 13:07 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
        • J Offline
          J Offline
          JoeCFD
          wrote on 12 Jan 2023, 15:10 last edited by JoeCFD 1 Dec 2023, 15:14
          #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
          • M Offline
            M Offline
            mrdebug
            wrote on 13 Jan 2023, 20:44 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
            • K Offline
              K Offline
              Kent-Dorfman
              wrote on 14 Jan 2023, 00:31 last edited by
              #6

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

              J 1 Reply Last reply 14 Jan 2023, 12:14
              0
              • K Kent-Dorfman
                14 Jan 2023, 00:31

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

                J Offline
                J Offline
                JonB
                wrote on 14 Jan 2023, 12:14 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

                1/7

                12 Jan 2023, 09:47

                • Login

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