Page 1 of 1

Timestamp sync-ing

Posted: 18 Apr 2012 21:05
by prino
Is there a smart way using a script to set all timestamps of all files in a folder (on a file by file basis) to the "Modified" timestamp of each file.

Why?

Many archives only store the "modilfied" timestamp and when these are unarchived the other two (created & accessed) are set to "now", which leads to the curious situation than a file is modified before it's created. Using the properties this is correctable via cut&paste, but doing so for large archives is a bit tedious.

Re: Timestamp sync-ing

Posted: 18 Apr 2012 21:52
by highend
::msg property("Write");

Use that in the address bar after selecting one of your files and tell me if it delivers the time that you want to set.

Re: Timestamp sync-ing

Posted: 18 Apr 2012 22:06
by prino
highend wrote:::msg property("Write");

Use that in the address bar after selecting one of your files and tell me if it delivers the time that you want to set.
Yes, it does

Re: Timestamp sync-ing

Posted: 18 Apr 2012 23:16
by highend
EDIT: Please post a timestamp from a few of your files (I want to see which format is used on your locale)

Create a new folder, copy one of your files to this folder, jump into this folder.

Use the script.

Get the properties tab of this file and check if all times are exactly equal to the modified time of your file.
If not, change $hMod and $sMod to accommodate your time differences (hMod = +- modified hours, the same for seconds).

Repeat the process until everything is right.

If you don't want the script to set the timestamps recursively, remove the second "r" in the:

Code: Select all

$files = folderreport("files", "r", , "r", , "|");
line!

Use it at your own risk, too lazy to implement any checks now :)

I' have to modify it a bit to avoid non allowed times... Stay tuned.

[/code]

Re: Timestamp sync-ing

Posted: 19 Apr 2012 08:27
by prino
Script seems to have fallen through?

Anyway, my timestamps are of the "2012-01-20 17:38:06" format

Re: Timestamp sync-ing

Posted: 19 Apr 2012 10:00
by highend
Script seems to have fallen through?
No, I've removed it intentionally.

Code: Select all

	$hMod = "";
	$sMod = "";
	$files = folderreport("files", "r", , , , "|");
	$string = "";
	foreach($item, $files, "|") {
		$mTime = property("Write", $item);
		$nDate = gettoken($mTime, 1, " ");
		$nTime = gettoken($mTime, 2, " ");
		$nmTime = (gettoken($nTime, 1, ":") + $hMod) . ":" . gettoken($nTime, 2, ":") . ":" . gettoken($nTime, 3, ":") + $sMod;
		timestamp ca, "$nDate $nmTime", $item;
		$string = $string . $item . " was set to: " . "$nDate $nmTime" . <crlf>;
	}
	text $string;
Use it with ONE single file in a test folder! After running it, tell me if you see any time differences. If everything is ok, you can use it on a normal folder. I removed the recursive flag in the folderreport command myself.

Re: Timestamp sync-ing

Posted: 19 Apr 2012 10:16
by prino
It works and it doesn't work... Some timestamps are OK, but for most the created & modified times are one or two seconds more, and setting a timestamp to "23:59:59" will result in a error-box with "Invalid date: yyyy-mm-dd 0::0". Looking at the script (as a complete newbie) I cannot really see why this would be happening.

Re: Timestamp sync-ing

Posted: 19 Apr 2012 10:34
by highend
It has nothing to do with the script itself. I have the same issues because of the 2 sec time difference.

E.g.:
The original modified time property shows: 16:05:07
but if I overwrite it with ::timestamp m, "19.04.2012 16:05:07";

the new stamp will be 16:05:09;

It's a windows "feature"...

It can be fixed but you have to do a few more tests. I must know if the time difference (seconds or hours) are always the same or if they differ (sometimes 1 second, sometimes 2 or if the hour can be two hours off as well).

If that's the case, $hMod and $sMod could be set to accommodate these changes but I have to rewrite the script to check for time boundaries (e.g. 59 seconds original, the new time must be 1 minute, 1 second (on a two second time difference)).

Re: Timestamp sync-ing

Posted: 19 Apr 2012 12:53
by prino
Explain the "windows feature^H^H^H^H^H^Hannoyance", as it doesn't occur with any other timestamp changing tools (Romain Petges "Attribute Changer", kish "PropertiesPlus", GNU's touch) and of course the properties pane in XY.

Re: Timestamp sync-ing

Posted: 19 Apr 2012 12:59
by highend
I don't think that that Don recreated a timestamp writing feature instead of calling a windows function for it.

https://startpage.com/do/search?languag ... difference

If any of these utilities correct this issue by themselfes, fine, use them.

Re: Timestamp sync-ing

Posted: 19 Apr 2012 14:11
by prino
highend wrote:I don't think that that Don recreated a timestamp writing feature instead of calling a windows function for it.

https://startpage.com/do/search?languag ... difference

If any of these utilities correct this issue by themselfes, fine, use them.
Don's do-it-in-the properties pane (using Cut&Paste) works flawlessly, but it's just not suitable for doing it to dozens of files created from unzipping an archive.

And as for the utilities which don't have the seconds-off issue,
  • All of them can process a whole directory, but cannot do the whole-directory processing on a file-by-file basis
  • GNU's touch cannot change the creation date
  • PropertiesPlus and Attribute Changer only work as GUI
  • PropertiesPlus no longer works on W64
  • Attribute Changer is 64-bit shell extension and as such doesn't work in XY
Is there a way to invoke a program from a script for every file in a directory, passing it the modified timestamp as argument? If yes, then I found something that might do the trick, Touch32, a command-line touch utility that can set all three dates.

Re: Timestamp sync-ing

Posted: 19 Apr 2012 14:18
by highend
Help - Advanced Topics - Scripting Commands Reference - get & run

and

Help - Advanced Topics - Scripting - Control Structures - Foreach Loops

Enough to get it running.

Re: Timestamp sync-ing

Posted: 19 Apr 2012 14:26
by prino
Thank you for the pointer, if I get stuck I'll come back.