Age of File in Hours

Questions about NeoBook PlugIns

Moderator: Neosoft Support

Locked
ajhunt
Posts: 266
Joined: Sat Apr 23, 2005 2:33 pm
Location: United Kingdom
Contact:

Age of File in Hours

Post by ajhunt »

Hi All, is there a simple action command to find the age of a file in just hours. i.e. FileName_X = 2 hours old or FileName_X = 48 hours old. Thanks Guys and any suggestions or scripts really appreciated. Regards Anthony.
Tony Kroos
Posts: 419
Joined: Thu Oct 15, 2009 3:43 pm

Re: Age of File in Hours

Post by Tony Kroos »

I believe you have already been told how to calculate age of file using vbscript
Here again:

Code: Select all

{NeoBook Function}
Version=5,80
Language=VBScript
Param=[%1]|FileName|Full path to file
Param=[%2]|Variable|Result variable
{End}
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objFile = objFS.GetFile("[%1]")
nbSetVar "[%2]", DateDiff("h",objFile.DateLastModified,Now)
Set objFile = Nothing
Set objFS = Nothing
If you want to check all files in folder then function can be improved to gain more speed:

Code: Select all

{NeoBook Function}
Version=5,80
Language=VBScript
Param=[%1]|Text|Select folder with files
Param=[%2]|Variable|Result variable
{End}
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFS.GetFolder("[%1]")
For Each file In objFolder.Files
Result = Result & file.Name & "=" & DateDiff("h",file.DateLastModified,Now) & vbcrlf
Next
nbSetVar "[%2]", Result
Set objFolder = Nothing
Set objFS = Nothing
ajhunt
Posts: 266
Joined: Sat Apr 23, 2005 2:33 pm
Location: United Kingdom
Contact:

Re: Age of File in Hours

Post by ajhunt »

Thank you Tony for your help, I must of missed the notification of help before. I appreciate your assistance and once again thank you. My apologies.
ajhunt
Posts: 266
Joined: Sat Apr 23, 2005 2:33 pm
Location: United Kingdom
Contact:

Re: Age of File in Hours

Post by ajhunt »

Hi again Tony, is there a way this can be done to find age of a file in minutes? Many thanks for your help again Tony. I appreciate it.
User avatar
dpayer
Posts: 1394
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Re: Age of File in Hours

Post by dpayer »

ajhunt wrote:Hi again Tony, is there a way this can be done to find age of a file in minutes? Many thanks for your help again Tony. I appreciate it.
Here is a project I did to get file/folder properties. I created a NB function to gather the info on files. You can use this to get the data and then parse it to the desired level:

viewtopic.php?t=19558

Image
David Payer
Des Moines, Iowa
USA
ajhunt
Posts: 266
Joined: Sat Apr 23, 2005 2:33 pm
Location: United Kingdom
Contact:

Re: Age of File in Hours

Post by ajhunt »

Hi David, thankyou very much for above. I will have a go but I really need the time created in minutes. Many thanks again for your time and effort to help.
User avatar
dpayer
Posts: 1394
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Re: Age of File in Hours

Post by dpayer »

ajhunt wrote:Hi David, thankyou very much for above. I will have a go but I really need the time created in minutes. Many thanks again for your time and effort to help.

Well, the example does display the minutes. It is your job to take that string of date and time and parse it so you get only the minutes part. That isn't so hard for they are fixed lengths. It is the operating system which retains and makes available those values. (same info that is generated when you do a DIR at a command line). Once you get what the OS offers, you manipulate it to fill your requirements.
David Payer
Des Moines, Iowa
USA
User avatar
Gaev
Posts: 3782
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada
Contact:

Re: Age of File in Hours

Post by Gaev »

ajhunt:

In recognition of all the hard work done on this by David Payer, I have created a vbscript function that should make it easy for you to get your desired result by doing something like this ...

Code: Select all

SetVar "[FileName]" "!c:\gk\Neo5\NBPlay5.exe"
SetVar "[fromTime]" "![Year]-[MonthNum]-[DayNum] [Time]"
Call "VBScript Examples\DavidPayerGetFileAgeInMinutes" "[FileName]" "[fromTime]" "[ageInMinutes]"
AlertBox "ageInMinutes" "[ageInMinutes]"
... and the file you need to place in the VBScript Examples sub folder of your NeoBook's Functions folder should look like ...

Code: Select all

{NeoBook Function}
Version=5.80
Language=VBScript
Param=[%1]|Text|Name of File
Param=[%2]|Text|From Time
Param=[%3]|Variable|Age In Minutes
{End}
NBselectedfile = "[%1]"
Set filesys = CreateObject("Scripting.FileSystemObject")
Set selectedfile = filesys.GetFile(NBselectedfile)
filecreatedate = selectedfile.DateCreated
ageInMinutes = DateDiff("n",filecreatedate,"[%2]")
publication.nbSetVar "[%3]", ageInMinutes
Thanks David ... feel free to add this to your rich set of file related functions
ajhunt
Posts: 266
Joined: Sat Apr 23, 2005 2:33 pm
Location: United Kingdom
Contact:

Re: Age of File in Hours

Post by ajhunt »

Thank you so much Geav and David - flip you guys are so dam helpful and so dam good too. May be simple to you, but when you don't know then it's basically imposible. Thank you guys for everything you do and helping. Very very much appreciated. Best regards Anthony.
Tony Kroos
Posts: 419
Joined: Thu Oct 15, 2009 3:43 pm

Re: Age of File in Hours

Post by Tony Kroos »

ajhunt wrote:Hi again Tony, is there a way this can be done to find age of a file in minutes? Many thanks for your help again Tony. I appreciate it.
http://www.w3schools.com/asp/func_datediff.asp
Replace h here
...
... DateDiff("h",obj....
...
by desired value, n for minutes
User avatar
Gaev
Posts: 3782
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada
Contact:

Re: Age of File in Hours

Post by Gaev »

Tony:

Sorry, I did not see your suggested vbscript code at the start of this post (before ajhunt changed his requirement from hours to minutes).

And my limited experience with vbscript did not extend to the availability of the Now function ... which negates the need to compose it from within NeoBook.
Locked