Age of File in Hours
Moderator: Neosoft Support
Age of File in Hours
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.
-
- Posts: 419
- Joined: Thu Oct 15, 2009 3:43 pm
Re: Age of File in Hours
I believe you have already been told how to calculate age of file using vbscript
Here again:
If you want to check all files in folder then function can be improved to gain more speed:
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
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
Re: Age of File in Hours
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.
Re: Age of File in Hours
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.
Re: Age of File in Hours
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: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.
viewtopic.php?t=19558
David Payer
Des Moines, Iowa
USA
Des Moines, Iowa
USA
Re: Age of File in Hours
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.
Re: Age of File in Hours
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
Des Moines, Iowa
USA
Re: Age of File in Hours
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 ...
... and the file you need to place in the VBScript Examples sub folder of your NeoBook's Functions folder should look like ...
Thanks David ... feel free to add this to your rich set of file related functions
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]"
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
Re: Age of File in Hours
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.
-
- Posts: 419
- Joined: Thu Oct 15, 2009 3:43 pm
Re: Age of File in Hours
http://www.w3schools.com/asp/func_datediff.aspajhunt 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.
Replace h here
...
... DateDiff("h",obj....
...
by desired value, n for minutes
Re: Age of File in Hours
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.
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.