Results 1 to 10 of 10

Thread: Is there such a way QFileInfo

  1. #1
    Join Date
    Aug 2007
    Posts
    275
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Is there such a way QFileInfo

    I would like to change the file's "lastModified" value but I cant find anything in Qt library that can do it .. I tried the c++ standard library but of no luck. can someone give a me a hint on how to fulfill my wish.....

    baray98

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Is there such a way QFileInfo

    Try opening the file for writing and closing it without writing anything.

  3. #3
    Join Date
    Oct 2007
    Location
    Cracow
    Posts
    56
    Thanks
    1
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Is there such a way QFileInfo

    in Win API there is function SetFileTime but it is only for windows, so try like Wysota write

  4. #4
    Join Date
    Aug 2007
    Posts
    275
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Is there such a way QFileInfo

    I guess i was not clear when i said changing the lastModified , what i meant was I want to change the lastModified stuff to whatever date and time i want ( it could be past or present , but mostly past ) , I want to preserve the file lastModified data from an FTP server, what happen is that when i started downloading I find that my date and time of my file is not the same as the server's. so my solution to this is to change the date and time of the file after download....

    I would say this is OS dependent but My app is just for windows .. so i can live with just windows stuff

    baray98

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Is there such a way QFileInfo

    In that case you can't do it with Qt. Why would you want to do that anyway? The file is modified when it is written to the device, not when its original was written to some other device.

  6. The following user says thank you to wysota for this useful post:

    baray98 (18th April 2008)

  7. #6
    Join Date
    Aug 2007
    Posts
    275
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Is there such a way QFileInfo

    I needed that info to be unchanged from the server.. so whatever is the last modified value from the server thats the time i should have in my downloaded copy. It will help me in many ways-thats why

    baray98

  8. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Is there such a way QFileInfo

    Why not store the value elsewhere? Or use platform dependent code as already suggested.

  9. #8
    Join Date
    Mar 2006
    Posts
    140
    Thanks
    8
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Is there such a way QFileInfo

    In that case you can't do it with Qt. Why would you want to do that anyway? The file is modified when it is written to the device, not when its original was written to some other device.
    Not entirely true. When you copy files cross device under windows (maybe linux and mac, not sure) the file time will be preserved.

    Why not store the value elsewhere? Or use platform dependent code as already suggested.
    I'm pretty sure it can be done using standard c, read a file's attributes into a 'struct stat' then change the member you're interested in then apply them back somehow.
    I did it years ago but can't remember how atm.

  10. #9
    Join Date
    Mar 2006
    Posts
    140
    Thanks
    8
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Is there such a way QFileInfo

    Hmm that was a dopey thing to say.
    The file creation time is set as the time written to the target device.

  11. #10
    Join Date
    Mar 2006
    Posts
    140
    Thanks
    8
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Is there such a way QFileInfo

    Actually I did it on a linux system, I think you need to use utime to do it.
    There doesn't seem to be any standard support for it, I think mainly because the FS stuff is so specific to the OS.

    Use utime for BSD and SetFileTime for windows. If you want it cross platform, you'll most likely need to write your own cross platform logic for it.

Similar Threads

  1. about QFileInfo
    By Pang in forum Qt Programming
    Replies: 1
    Last Post: 19th October 2006, 10:09

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.