Determine a Files Age

Downloads
37724.zip

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:\windows\notepad.exe

on my system results in the output NOTEPAD.EXE is 263 days old.

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish