English

How To: Get a file's date using Avenue

Summary

Note:
The information in this article applies to ArcView GIS versions 3.x only. The instructions described apply to the Avenue programming language, which is specific to the ArcView GIS application.

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

Procedure

  1. Open a new script window.
    1. Activate the Project window.
    2. Click the Scripts icon.
    3. 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")
    break
  end
end

f.Close

File.Delete (myFileName)

'-- End of Script: findfiledate.ave
  1. Select Compile from the Script menu or click the Script compile button.
    [O-Image] Script compile button
  2. Click the Run compiled script button to run the script.
    [O-Image] Run compiled script button