Determine a Files Age


Knowing the age of a file is useful for archiving and housekeeping purposes. In "Real-World Scripting: Deleting Files by Their Age" (June 2000,, 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

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


  • 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.