PDA

View Full Version : Is there such a way QFileInfo



baray98
18th April 2008, 05:36
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

wysota
18th April 2008, 07:21
Try opening the file for writing and closing it without writing anything.

mazurekwrc
18th April 2008, 08:28
in Win API there is function SetFileTime but it is only for windows, so try like Wysota write

baray98
18th April 2008, 09:27
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

wysota
18th April 2008, 16:37
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.

baray98
18th April 2008, 19:34
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

wysota
18th April 2008, 19:43
Why not store the value elsewhere? Or use platform dependent code as already suggested.

stevey
21st April 2008, 02:57
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.

stevey
21st April 2008, 03:47
Hmm that was a dopey thing to say.
The file creation time is set as the time written to the target device.
:o

stevey
21st April 2008, 04:23
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.