Windows command line utility that will increase the date modified/created of a file to "current time + 1 day"?

meirionwyllt
meirionwyllt used Ask the Experts™
on
I have used utilities like touch.exe and FileTouch.exe that can set a file's date modified/created to the current system time.  But what I want is to set a file's date modified/created to one day later than the current system time.  Could anyone write a batch file that would do this, using touch.exe or whatever?  Or any other way, like PowerShell?

Thanks.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2018
Distinguished Expert 2018

Commented:
As a one-liner in Powershell:
$Item = Get-Item "C:\Temp\touch.txt"; $TouchDate = (Get-Date).AddDays(1); "CreationTime", "LastWriteTime" | % {$Item.$_ = $TouchDate}

Open in new window

This could of course be turned into a function with parameters; how flexible do you need to be in terms of the new date?
meirionwylltSenior Desktop Engineer

Author

Commented:
Great stuff - that works!

Can I just modify this silghtly to put it in my real-world situation?

There *.ade files in \\domain.local\adnoddau\cgsd\Cronfeydd Data\Newydd

I want the script to do the "+1 day" as above for all *.ade files in that folder, and then move all these *.ade files into this folder \\domain.local\adnoddau\cgsd\Cronfeydd Data, overwriting what's already there.

Could you incorporate this as well?

Many thanks.
Most Valuable Expert 2018
Distinguished Expert 2018
Commented:
This should do the trick; short version for copy and paste into a PS console:
$Source = "\\domain.local\adnoddau\cgsd\Cronfeydd Data\Newydd\*.ade"
$Target = "\\domain.local\adnoddau\cgsd\Cronfeydd Data"
$TouchDate = (Get-Date).AddDays(1)
Get-ChildItem -Path $Source -File | % {"Touching and moving $($_.Name) ..." | Write-Host; $_.CreationTime = $TouchDate; $_.LastWriteTime = $TouchDate; Move-Item -Path $_.FullName -Destination $Target -Force -ErrorAction Continue}

Open in new window

Expanded version:
$Source = "\\domain.local\adnoddau\cgsd\Cronfeydd Data\Newydd\*.ade"
$Target = "\\domain.local\adnoddau\cgsd\Cronfeydd Data"
$TouchDate = (Get-Date).AddDays(1)
Get-ChildItem -Path $Source -File |
	ForEach-Object {
		"Touching and moving $($_.Name) ..." | Write-Host
		$_.CreationTime = $TouchDate
		$_.LastWriteTime = $TouchDate
		Move-Item -Path $_.FullName -Destination $Target -Force -ErrorAction Continue
	}

Open in new window

meirionwylltSenior Desktop Engineer

Author

Commented:
Excellent work - thank you!  Points well deserved.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial