Determine a Files Age
Use WSH to determine the age of a file.
February 10, 2003
Knowing the age of a file is useful for archiving and housekeeping purposes. In "Real-World Scripting: Deleting Files by Their Age" (June 2000, http://www.winscriptingsolutions.com, InstantDoc ID 8799), Dick Lewis presents a Perl script that checks files' ages and deletes files that are older than the age you specify. Dick's script requires that you download and install Perl for Win32. I wrote an alternative script, which Listing 3 shows, that uses Windows Script Host's (WSH's) standard features to calculate files' ages. My script uses the File System Object's (FSO's) File.DateCreated property and the Now function that returns the current date and time. The difference between these two values tells you a file's age. To use the script, go to a command prompt and enter
Cscript fileage.vbs Path_and_Name_of_File
For example, entering
Cscript fileage.vbs c:windowsotepad.exe
on my system results in the output NOTEPAD.EXE is 263 days old.
—Wilfred Wright
[email protected]
About the Author
You May Also Like