topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • October 14, 2019, 08:27 AM
  • Proudly celebrating 13 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: How old is this file?  (Read 1304 times)

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 419
    • View Profile
    • Donate to Member
How old is this file?
« on: December 28, 2018, 06:26 PM »
Looking for a little snack program that does the following:

-- Place shortcut to it in SendTo list.

-- Send a file to it.

-- Up pops window saying how old the file is.

-- Days.  Hours.  Minutes.

Any help or thoughts appreciated!

Nicholas Kormanik



magician62

  • Supporting Member
  • Joined in 2011
  • **
  • Posts: 153
    • View Profile
    • Donate to Member
Re: How old is this file?
« Reply #1 on: December 29, 2018, 05:07 AM »
I tend to just properties a file to get a date. as I do the age bit in my head, and rarely care about Hours and Minutes

I can't code anything, but can prompt a couple of questions that may arise.

The important thing is how are you determining the age of the file?

Days since created?
Days since modified?

Date created is NOT always the older of the two? File copied form another location for example.


nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 419
    • View Profile
    • Donate to Member
Re: How old is this file?
« Reply #2 on: December 29, 2018, 05:23 AM »
The files are freshly created, less than 38 hours old, so far.  Creation Date and Modified Date appear to be the same.  Either one will do.

I've been searching on the Internet and no one out there seems to have come up with a solution, though it seems so easy -- Current Time minus (say) Creation Date.

No big deal.  Just wondered if someone here could whip it out.


4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,234
    • View Profile
    • Donate to Member
Re: How old is this file?
« Reply #3 on: December 29, 2018, 06:30 AM »
DaysSince.ps1

2018-12-29.jpgHow old is this file?

Shortcut in the archive, (assuming Win10), drop it into C:\Users\<user>\appdata\roaming\microsoft\windows\sendto - you'll need to edit the target path to the PowerShell script if it's different from C:\PoSh (my test folder).

Shortcut target:
Code: Text [Select]
  1. C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -WindowStyle Hidden -File C:\PoSh\DaysSince.ps1

Code: PowerShell [Select]
  1. <#
  2.   DaysSince.ps1 <file>
  3. #>
  4.  
  5. Param (
  6.   $SourceFile
  7. )
  8.  
  9. $fp = (Get-ItemProperty -Path $SourceFile)
  10.  
  11. $deltaM = (New-TimeSpan -Start $fp.LastWriteTime -End (Get-Date))
  12. $deltaC = (New-TimeSpan -Start $fp.CreationTime -End (Get-Date))
  13.  
  14. $text = "$([io.path]::GetFileName($SourceFile))`r`nTime since:`r`nCreation:`t`t$($deltaC.Days) Days, $($deltaC.Hours) Hours, $($deltaC.Minutes) Minutes`r`n"
  15. $text += "Modification:`t$($deltaM.Days) Days, $($deltaM.Hours) Hours, $($deltaM.Minutes) Minutes"
  16.  
  17. $wshell = New-Object -ComObject Wscript.Shell -ErrorAction Stop
  18. $wshell.Popup($text, 0, "DaysSince", 64) | Out-Null

NOTE: I'm running PowerShell 5.x, I don't know if it will work on a lower version.

No doubt there'll be some Windows weirdness that will stop it from running, took ages to work out why it wasn't passing files with spaces in.

And no doubt you'll run afoul of PowerShell's stringent ExecutionPolicy setting, if that happens change the Shortcut Target to:
Code: Text [Select]
  1. C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -WindowStyle Hidden -File C:\PoSh\DaysSince.ps1
« Last Edit: December 29, 2018, 06:36 AM by 4wd »

Curt

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 7,532
    • View Profile
    • Donate to Member
Re: How old is this file?
« Reply #4 on: December 30, 2018, 06:53 AM »
I have certain files in "Last Used..." order. If I want to know more about the various dates, concerning a file, I right-click it and click "FileMenu Tools..." > "Change File Time". Clicking it, does of course not mean I also would have to change anything. But it will tell me some important dates;


2018-12-30.jpgHow old is this file?

€10 https://www.lopesoft...oducts/filemenutools

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 419
    • View Profile
    • Donate to Member
Re: How old is this file?
« Reply #5 on: December 30, 2018, 07:46 PM »
4wd, wow, amazing.  You nailed it.  Terrific job.

Hope this gem helps others out there.

Skwire, mission accomplished.

Happy New Year to all.