Editing Files Attributes

English support forum

Moderators: Hacker, petermad, Stefan2, white

Post Reply
RickyGold
Junior Member
Junior Member
Posts: 18
Joined: 2008-09-23, 13:51 UTC

Editing Files Attributes

Post by *RickyGold »

Hi all.
I need to batch-edit the writetime attribute of selected files, adding or subtructing a fixed amount of time (shift), relative to the actual writetime itself.
I found some useful advise in this topic:
http://ghisler.ch/board/viewtopic.php?p=120698
but at the moment I'm stuck to the impossibility to place an expression in the "value" field (well this didn't really surprised me, because I was aware of pushing the field functionality beyond its purpose...).
My try was looking something like this: (adding 3 hours to the timestamp, in this example):

[x] change plugin attribute:
"tc.writetime" = "[=tc.writetime.h+03]"

Can someone please give me an advise on how to obtain this?
Thank you very much.
User avatar
Gral
Power Member
Power Member
Posts: 1609
Joined: 2005-01-26, 15:12 UTC

Post by *Gral »

What you actual need is AddTime utility. Get it on http://www.totalcmd.net/plugring/addtime_addon.html and put on the toolbar with %L parameter.
RickyGold
Junior Member
Junior Member
Posts: 18
Joined: 2008-09-23, 13:51 UTC

Post by *RickyGold »

Thank you Gral, your suggestion was very useful.
Unfortunately, while fitting perfectly on file attributes, the addon behavior on selected directories is not as needed; Instead of modifying the writetime of the directory itself, the addon modify the writetime of each file contained in it.
I'm checking a way to work this thing out - any additional advise is greatly appreciated, of course.
User avatar
jinsight
Senior Member
Senior Member
Posts: 299
Joined: 2003-02-25, 19:47 UTC
Location: Wooster, Ohio, USA

Post by *jinsight »

Try freeware Bulk Rename Utility. Go to Options, timestamp for incremental time changes
License #1945
Windows 10 Pro x64
Version 22H2 (OS Build 19045.3930)
TC 11.00 x64 and x86, Everything 1.5.0.1366a x64, QAP 11.6.3.1 x64
User avatar
Hacker
Moderator
Moderator
Posts: 13144
Joined: 2003-02-06, 14:56 UTC
Location: Bratislava, Slovakia

Post by *Hacker »

BTW, AddTime.ahk:

Code: Select all

IfLess, 0, 7
	Goto, ShowHelp
IfGreater, 0, 9
	Goto, ShowHelp

IfEqual, 1, +
	Add = 1
Else
	IfEqual, 1, -
		Add = 0
	Else
	    Goto, ShowHelp

Years = %2%
Months = %3%
Days = %4%
Hours = %5%
Minutes = %6%
Seconds = %7%
RecurseVar = 0
FilePattern = *.*

If %8%
{
	IfEqual, 8, r
	{
		RecurseVar = 1
		If %9%
		{
			FilePattern = %9%
		}
	}
	Else
		FilePattern = %8%
}

StringLen, Len, Years
Len := (4 - Len)
Loop, %Len%
	Years = 0%Years%

StringLen, Len, Months
Len := (2 - Len)
Loop, %Len%
	Months = 0%Months%

StringLen, Len, Days
Len := (2 - Len)
Loop, %Len%
	Days = 0%Days%

StringLen, Len, Hours
Len := (2 - Len)
Loop, %Len%
	Hours = 0%Hours%

StringLen, Len, Minutes
Len := (2 - Len)
Loop, %Len%
	Minutes = 0%Minutes%

StringLen, Len, Seconds
Len := (2 - Len)
Loop, %Len%
	Seconds = 0%Seconds%

Loop, %FilePattern%, 1, %RecurseVar%
{
	FileGetTime, TimeStamp, %A_LoopFileFullPath%
	If Add
		EnvAdd, TimeStamp, Years Months Days Hours Minutes Seconds
	Else
        EnvSub, TimeStamp, Years Months Days Hours Minutes Seconds
	FileSetTime, TimeStamp, %A_LoopFileFullPath%
	If ErrorLevel
		MsgBox, Error: Failed to set time of '%A_LoopFileFullPath%'
}
Return

ShowHelp:
	MsgBox,
(
Usage:
%A_ScriptName% <+|-> <years months days hours minutes seconds> [r] [file_mask]

+ or -: + means add time, - means subtract ;-)
years - seconds: Provide a number for each, a 0 for unneeded values
r: Work recursively, ie change the time of all files specified by file_mask in all subdirectories
file_mask: Specify a file mask to use. Default is *.*

Example:
%A_ScriptName% + 0 0 0 2 8 0
Changes the time of all the files in the current directory by + 2 hours, 8 minutes
)
Return
Roman
Mal angenommen, du drückst Strg+F, wählst die FTP-Verbindung (mit gespeichertem Passwort), klickst aber nicht auf Verbinden, sondern fällst tot um.
RickyGold
Junior Member
Junior Member
Posts: 18
Joined: 2008-09-23, 13:51 UTC

Post by *RickyGold »

Thanks for all replies.
At the moment I'm trying to modify the code suggested by Hacker, to have it working on files and folders selected inside the TC panel instead of using a command-line parameter - so I'm fiddling around Postmessage, etc. :-)
News to come (I hope).
User avatar
Hacker
Moderator
Moderator
Posts: 13144
Joined: 2003-02-06, 14:56 UTC
Location: Bratislava, Slovakia

Post by *Hacker »

RickyGold,
Just change the Loop to parse a TC %L list.

Roman
Mal angenommen, du drückst Strg+F, wählst die FTP-Verbindung (mit gespeichertem Passwort), klickst aber nicht auf Verbinden, sondern fällst tot um.
RickyGold
Junior Member
Junior Member
Posts: 18
Joined: 2008-09-23, 13:51 UTC

Post by *RickyGold »

I had to correct some things to have the script working (WinXP SP3 + AutoHotkey v1.1.11.01).
  • 1) Took away Years and Months variables, since the EnvAdd instruction doesn't manage them; Rewrote the EnvAdd code portion to have it properly recognize the "TimeUnit" variables property.
    2) Took away digit number control and sign control on command line parameters, since the EnvAdd instruction can handle itself signed variables of different digit length (tried 1 to 3 signed digit variables, Ok).
    3) Used the freed 1st parameter (+|-) as parameter to process TimeStamp of Files only, Folders only or both Files and Folders (A|F|D).
    Recursive and filemask parameters working fine.
Compiled as .exe file, placed in the "Addon" TC directory, and associated to a button in the toolbar with specified parameters.

At the moment it's working fine on all files and folders present in the selected panel; I still have to:
  • 1) Have it working in the Listbox (actually it doesn't), since I use Alt-F7 to search for files and folders with a given timestamp interval, and then "feed" them to the Listbox for the purpose of Timeshifting them.
    2) Have it working ONLY on the file under cursor OR on SELECTED files, not on ALL the files in the panel as now.
I will carry on, for the moment here is how the modified script looks like:

Code: Select all

IfLess, 0, 5
   Goto, ShowHelp
IfGreater, 0, 7
   Goto, ShowHelp

IfEqual, 1, F
   Target = 0
Else IfEqual, 1, D
   Target = 2
Else IfEqual, 1, A
   Target = 1
Else
   Goto, ShowHelp



Dn = %2%
Hn = %3%
Mn = %4%
Sn = %5%
RecurseVar = 0
FilePattern = *.*



If %6%
{
   IfEqual, 6, R
   {
      RecurseVar = 1
      If %7%
      {
         FilePattern = %7%
      }
   }
   Else
      FilePattern = %6%
}



Loop, %FilePattern%, %Target%, %RecurseVar%
{
   FileGetTime, TimeStamp, %A_LoopFileFullPath%
      EnvAdd, TimeStamp, Dn, days
      EnvAdd, TimeStamp, Hn, hours
      EnvAdd, TimeStamp, Mn, minutes
      EnvAdd, TimeStamp, Sn, seconds
   FileSetTime, TimeStamp, %A_LoopFileFullPath%
   If ErrorLevel
      MsgBox, Error: Failed to set time of '%A_LoopFileFullPath%'
}
Return



ShowHelp:
MsgBox,
(
Usage:
%A_ScriptName% <F|D|A> <days hours minutes seconds> [R] [file_mask]

F : Process Files only
D : Process Folders only
A : Process both Files and Folders

days - seconds : signed TimeShift values, 0 for unneeded values
R: Work recursively, ie change the time of all files specified by file_mask in all subdirectories
file_mask: Specify a file mask to use. Default is *.*

Example:
%A_ScriptName% A 0 2 -8 0
Shift the timestamp of both Files and Folders in the current directory,
adding 2 hours and subtracting 8 minutes.
)
Return
Post Reply