Change date relative to existing file date minus 1 year?

English support forum

Moderators: white, Hacker, petermad, Stefan2

Post Reply
jj42
Junior Member
Junior Member
Posts: 50
Joined: 2007-08-18, 23:17 UTC

Change date relative to existing file date minus 1 year?

Post by *jj42 »

Hi,

is it possible to change the date/time of files relative to their existing date/time?
E.g., the selected files have a date of 2016-12-12 and 2017-03-01 and I want to change the filedates back a year so that the new dates would be 2015-12-12 and 2016-03-01.

Or (maybe more common) the time needs to be changed by a certain amount, e.g. if a camera was on a wrong setting.

With the "Change Attributes" dialogue, it only seems possible to set a fixed date, not a relative one.
User avatar
Stefan2
Power Member
Power Member
Posts: 4133
Joined: 2007-09-13, 22:20 UTC
Location: Europa

PowerShell: ForEachFileDo_TIMESTAMP.ps1 Adjust add min year

Post by *Stefan2 »

Or use PowerShell

Pure PowerShell syntax:

Code: Select all

GCI | ForEach{ $_.LastWriteTime = ($_.LastWriteTime).AddYears(-1) }
- - -

Here is a whole script to use with Total Commander.

- save the code to TC folder as "ForEachFileDo_TIMESTAMP.ps1"

- add a button

Cmd = Powershell -NoProfile -NoExit -ExecutionPolicy Unrestricted "%COMMANDER_PATH%\ForEachFileDo_TIMESTAMP.ps1"
Param="%L"
[X] Run minimized


Select all files and execute this script. Done.

- - -

A very simple script:

Code: Select all

# the 
TYPE $Args[0] | ForEach{$F=(Get-Item($_));$F.LastWriteTime=($F.LastWriteTime).AddYears(-1)}

- - -

Full script:

Code: Select all

# PowerShell Script for Total Commander
# Stefan, 14. March 2017
# http://ghisler.ch/board/viewtopic.php?t=47504
# Adjust timestamp of all selected files
#
# Example:
#  FROM:
#    24.12.2001
#  TO:
#    24.12.2000
#
# Usage:
#  Create TC button
#    Cmd=Powershell -NoProfile -NoExit -ExecutionPolicy Unrestricted "%COMMANDER_PATH%\ForEachFileDo_TIMESTAMP.ps1"
#    Param="%L"
#    [X] Run minimized
#
#       Tip: remove '-NoExit' to let the console window close after work.
#
# Select all files and execute this script. Done.
#
#
# ==============================================================================
# // The script

# // Check arguments:
If ($Args.Count -eq 0) { "Please use '%L' as TCs parameter. Also select one or more files first. Script quits here."; return}

# //DEBUG:
# Notepad $Args[0]
# TYPE $Args[0]

# //Prompt the user:
$a = new-object -comobject wscript.shell
$b = $a.popup("Continue changing timestamp? (Inspect script first)",0,"Change Timestamp",1)
if ($b -eq 2){
    # Write-Host "You pressed Cancel. Script quits here.`n`n`nPress any key to close..."
    # $x = $host.UI.RawUI.ReadKey()
    Return
    }

# //Do the WORK:
 TYPE $Args[0] | ForEach{$F=(Get-Item($_));$F.LastWriteTime=($F.LastWriteTime).AddYears(-1)}
 
 
# -----------------------------------------------------------------
# // some alternatives:

#   CreationTime
#   LastWriteTime
#   LastAccessTime

#    AddDays
#    AddHours
#    AddMilliseconds
#    AddMinutes
#    AddMonths
#    AddSeconds
#    AddTicks
#    AddYears
#    Usage:
#    AddYears(2)    # add plus two years
#    AddYears(-4)   # extract minus four years
# -----------------------------------------------------------------

# // or: adjust days and hours and more at the same time
# $MyTimeStamp = New-TimeSpan -Days 1 -Hours 2 -Minutes 30
# TYPE $Args[0] | ForEach{$F=(Get-Item($_));$F.LastWriteTime=($F.LastWriteTime) + $MyTimeStamp}
# -----------------------------------------------------------------
# // or: set time only
#TYPE $Args[0] | ForEach{$F=(Get-Item($_));$F.LastWriteTime= "07:55:56"}
# -----------------------------------------------------------------
# // or: set whole new date (MONTH.DAY.YEAR format depends on your system settings)
# Suppose today is August 31, 2007. In the US, we’d list the date like this: 8/31/2007, the format being month/day/year. 
# In a very large portion of the world, however, that same date is listed like this: 31/8/2007, the format being day/month/year.
# https://technet.microsoft.com/en-us/library/ee692801.aspx
# TYPE $Args[0] | ForEach{$F=(Get-Item($_));$F.LastWriteTime= "12.24.2005 07:07:34"}
# First of April at midnight:
# TYPE $Args[0] | ForEach{$F=(Get-Item($_));$F.LastWriteTime= "4.1.2005 00:00:00"}
# -----------------------------------------------------------------
# Pure PowerShell syntax:
# GCI | ForEach{ $_.LastWriteTime = ($_.LastWriteTime).AddYears(-1) }
# -----------------------------------------------------------------

#  Create TC button
#    Cmd=Powershell -NoProfile -NoExit -ExecutionPolicy Unrestricted "%COMMANDER_PATH%\ForEachFileDo_TIMESTAMP.ps1"
#    Param="%L"
#    [X] Run minimized

REM TOTALCMD#BAR#DATA
REM Powershell -NoProfile -NoExit -ExecutionPolicy Unrestricted  %COMMANDER_PATH%\TOOLs\CMDs\ForEachFileDo_TIMESTAMP.ps1
REM "%L"
REM C:\Windows\System32\WindowsPowerShell\v1.0\powershell_ise.exe,1
REM ForEachFileDo_TIMESTAMP.ps1
REM 
REM 1
REM -1
# -----------------------------------------------------------------


HTH? :D
jj42
Junior Member
Junior Member
Posts: 50
Joined: 2007-08-18, 23:17 UTC

Post by *jj42 »

Thank you both, I will try the addons first!

Installing Powershell just for this might be overkill. But it looks like a swiss army knife solution for any future problems... ;)

Maybe this date/time-shift could be a built-in feature of TC someday? (I'll submit a feature request :D )
User avatar
MVV
Power Member
Power Member
Posts: 8702
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

jj42,
PowerShell is installed by default since Windows 7.
jj42
Junior Member
Junior Member
Posts: 50
Joined: 2007-08-18, 23:17 UTC

Post by *jj42 »

PowerShell is installed by default since Windows 7.
Oh, I did not know that.... checking... yes, it's here :)
Thanks for the heads-up, I may try using it, too.
User avatar
Phred
Senior Member
Senior Member
Posts: 375
Joined: 2009-06-16, 15:24 UTC
Location: SEAu

Or Add-ons

Post by *Phred »

Or use the add-ons provided by Hacker, a regular here.

See:
ReDate or AddTime on this page:
http://www.ghisler.com/tools.htm
Regards, PhredE
Licence holder since 1999
Awaiting a $D donors-token for the title-bar so we can display that we have donated further.
User avatar
Phred
Senior Member
Senior Member
Posts: 375
Joined: 2009-06-16, 15:24 UTC
Location: SEAu

Re: Or Add-ons

Post by *Phred »

Phred wrote:Or use the add-ons provided by Hacker, a regular here.

See:
ReDate or AddTime on this page:
http://www.ghisler.com/tools.htm
Make sure you update to the latest version of Redate, 1.1.2 - March 2013.
Earlier versions tend to lose themselves: 30th February, for example.

PS Roman, thanks for enlarging Redate's window, but it's a bit large and off-screen, isn't it? And you don't remember my resize, nor placement. :(
PPS AddTime's fairly tiny on todays screens, don't you think? And squidgy little spinners..? :)
Last, Redate: you don't correctly remember the old dates. :|
But thanks.
User avatar
Hacker
Moderator
Moderator
Posts: 13052
Joined: 2003-02-06, 14:56 UTC
Location: Bratislava, Slovakia

Post by *Hacker »

Phred,
Oh I am sure there are much better alternatives meanwhile. :)

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.
User avatar
Phred
Senior Member
Senior Member
Posts: 375
Joined: 2009-06-16, 15:24 UTC
Location: SEAu

Orly?

Post by *Phred »

Hacker wrote:Phred,
Oh I am sure there are much better alternatives meanwhile. :)

Roman
True?
Can you point us to them?
User avatar
Hacker
Moderator
Moderator
Posts: 13052
Joined: 2003-02-06, 14:56 UTC
Location: Bratislava, Slovakia

Post by *Hacker »

Phred,
Not really. :D

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.
User avatar
Phred
Senior Member
Senior Member
Posts: 375
Joined: 2009-06-16, 15:24 UTC
Location: SEAu

Re-dating Files

Post by *Phred »

Anyone?

'Changing the dates of a set of files, incrementing dates/times by relative amounts.'

I recently redated a set of podcast files, giving each a date one week apart, starting from the date the first one was broadcast on.


Windows Photo Gallery can change the date/times of a set of photos/videos but only on a sliding basis, en mass. A selected group can be re-dated by a certain amount - but not each individually wrt each other.

Hacker's Redater does this; it's just very basic and and doesn't have a likable VMU.
Visual Method of Use (GUI).
Regards, PhredE
Licence holder since 1999
Awaiting a $D donors-token for the title-bar so we can display that we have donated further.
User avatar
Horst.Epp
Power Member
Power Member
Posts: 6450
Joined: 2003-02-06, 17:36 UTC
Location: Germany

Post by *Horst.Epp »

Windows 11 Home x64 Version 23H2 (OS Build 22631.3374)
TC 11.03 x64 / x86
Everything 1.5.0.1371a (x64), Everything Toolbar 1.3.2, Listary Pro 6.3.0.69
QAP 11.6.3.2 x64
User avatar
jinsight
Senior Member
Senior Member
Posts: 299
Joined: 2003-02-25, 19:47 UTC
Location: Wooster, Ohio, USA

Post by *jinsight »

See also

NewFileTime 2.99
http://www.softwareok.com/?seite=Microsoft/NewFileTime
NewTime increments or decremants only the file date relative to the file's own date by a fixed number of days.

Bulk Rename Utility 3.0.0.1
http://www.bulkrenameutility.co.uk/Main_Intro.php
The section on Changing File Timestamps
Bulk Rename Utility increments or decrements the file date, hours, minutes and seconds relative to the file's own timestamp by a fixed number of days, hours, minutes or seconds.

BulkFileChanger v1.51
http://www.nirsoft.net/utils/bulk_file_changer.html
Bulk File Changer increments and decrements the file date, hours, minutes and seconds relative to the file's own timestamp or a reference date by a fixed amount or a sequential amount of years, months, days, hours, minutes or seconds.
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
Post Reply