How To: Get a file's date using Avenue


This article demonstrates how you can use Avenue to return the date of a file.


  1. Open a new script window.

    A. Activate the Project window.
    B. Click the Scripts icon.
    C. Click New.

  2. Paste the following code into the script window:

    '-- Script: findfiledate.ave

    '-- The script can only get file date information for files that are
    '-- 8.3 compliant in directory structures that are 8.3 compliant.

    fnSearch = FileDialog.Show("*.*","*.*","Pick file to get its date.").AsString
    myFileNameStr = "C:\junk.txt"
    myFileName = myFileNameStr.AsFileName

    '-- Depending on your operating system, the path to the file command.com
    '-- may need to be adjusted. The best way to ensure that the script will
    '-- run properly is to search for the file command.com on your hard
    '-- drive with Windows Explorer or File Manager and replace that path
    '-- with the one in the System.Execute statement. For example. if you
    '-- have Windows 3.1 you may need to change your System.Execute
    '-- statement to look like:
    '-- System.Execute("c:\command.com /c dir /s "+ fnSearch + " >"+myFileNameStr)

    System.Execute("c:\winnt\system32\command.com /c dir /s " + fnSearch +
    " >"+ myFileNameStr)

    '-- Due to the delay of the operating system in searching for the
    '-- file in the directory structure from the above System.Execute
    '-- statement it is necessary to pause the execution of the rest of
    '-- the Avenue script for a few seconds. For faster Pentium systems a
    '-- two second delay should be sufficient. For slower systems
    '-- the number may need to be increased (in some case up to a ten
    '-- second delay may be required).

    start = date.now.asseconds
    while (date.now.asseconds <> (start + 2)) '-- change '2' to meet your system needs end

    f = LineFile.Make(myFileName, #FILE_PERM_READ)
    sizeofLineFile = f.GetSize
    listofPathStringPieces = fnSearch.AsTokens("\.")
    fnSearchPrefix = listofPathStringPieces.Get(listofPathStringPieces.Count -2)
    fnSearchSuffix = listofPathStringPieces.Get(listofPathStringPieces.Count -1)
    for each i in 0..(sizeofLineFile - 1)
    thisLine = f.ReadElt
    if ((thisLine.Contains(fnSearchPrefix)) and
    (thisLine.Contains(fnSearchSuffix))) then
    dateString = thisLine.Extract(3)
    MsgBox.Info("FileName: "+ fnSearch +NL+ "is dated " + dateString,"Done")


    File.Delete (myFileName)

    '-- End of Script: findfiledate.ave

  3. Select Compile from the Script menu or click the
    [O-Image] Script compile button
  4. Click the
    [O-Image] Run compiled script button
    button to run the script.