Source language: Translate to:

Age of File in Hours

Questions about NeoBook PlugIns

Moderator: Neosoft Support

Age of File in Hours

Postby ajhunt » Thu Dec 10, 2015 6:05 am

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.
ajhunt
 
Posts: 215
Joined: Sat Apr 23, 2005 2:33 pm
Location: United Kingdom

Re: Age of File in Hours

Postby Tony Kroos » Thu Dec 10, 2015 1:50 pm

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
Tony Kroos
 
Posts: 402
Joined: Thu Oct 15, 2009 3:43 pm

Re: Age of File in Hours

Postby ajhunt » Fri Dec 11, 2015 4:13 am

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: 215
Joined: Sat Apr 23, 2005 2:33 pm
Location: United Kingdom

Re: Age of File in Hours

Postby ajhunt » Wed Jan 27, 2016 5:13 am

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.
ajhunt
 
Posts: 215
Joined: Sat Apr 23, 2005 2:33 pm
Location: United Kingdom

Re: Age of File in Hours

Postby dpayer » Wed Jan 27, 2016 9:06 am

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
User avatar
dpayer
 
Posts: 1380
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Re: Age of File in Hours

Postby ajhunt » Wed Jan 27, 2016 9:12 am

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.
ajhunt
 
Posts: 215
Joined: Sat Apr 23, 2005 2:33 pm
Location: United Kingdom

Re: Age of File in Hours

Postby dpayer » Wed Jan 27, 2016 11:20 am

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
dpayer
 
Posts: 1380
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Re: Age of File in Hours

Postby Gaev » Wed Jan 27, 2016 12:22 pm

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
User avatar
Gaev
 
Posts: 3717
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: Age of File in Hours

Postby ajhunt » Wed Jan 27, 2016 1:06 pm

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.
ajhunt
 
Posts: 215
Joined: Sat Apr 23, 2005 2:33 pm
Location: United Kingdom

Re: Age of File in Hours

Postby Tony Kroos » Wed Jan 27, 2016 5:55 pm

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
Tony Kroos
 
Posts: 402
Joined: Thu Oct 15, 2009 3:43 pm

Re: Age of File in Hours

Postby Gaev » Wed Jan 27, 2016 7:47 pm

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.
User avatar
Gaev
 
Posts: 3717
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada


Return to PlugIn Discussions

Who is online

Users browsing this forum: No registered users and 1 guest

cron