Database Solutions - Hints & Tips

Tip 19:
Discovering Information about a File

Problem

The UNIFACE proc statement filebox allows a user to select a file from the native file system. The full path of the file selected is returned to UNIFACE in $result e.g. c:\projects\hr\doc\memo.doc. On certain occasions it may be useful to derive further information about the file selected e.g. the size of the file or the date it was created.

Solution

The undocumented UNIFACE proc statement interrupt allows the UNIFACE developer to obtain the following information about a selected file;

  • name of the directory the file resides in
  • name of the file excluding the full path
  • file type
  • file version
  • file creation date
  • file attributes
  • record size
  • file size

In addition, the interrupt statement can be used to derive information about the directory structure of the native file system. For instance it is possible to obtain the name of the "current" directory or list the names of the files in the "current" directory.

Example of Usage

On a weekly basis a third party application creates a text file containing bank account details of new employees. At the end of each week the file has to be manually imported into a UNIFACE application. The UNIFACE application user uses a filebox to select the file to be imported. Once the file has been selected there is a requirement to display a warning message if the file is more than a week old or if the file has not been selected from the expected directory. This validation can be accomplished by using the interrupt proc statement to obtain the required information about the file.

Method

The syntax of the interrupt proc statement is as follows;

interrupt(n,path_file)

where n is an integer value and path_file is the full name of a directory path or the full name of a file which may be a string literal

e.g." c:\projects\hr\doc\memo.doc"

variable name e.g. $FILE_NAME_SELECTED$

field name e.g. FILE_NAME.MY_ENTITY

The interrupt statement returns information about a directory or file in $result.

Let us assume that the current directory is "c:\projects\hr\doc\". The following examples show how the interrupt statement can be used;

interrupt(0,"c:\projects\hr\doc\memo.doc")
returns comprehensive information about the specified file
e.g. "Path=;DiskDir=c:\projects\hr\doc\; Name=memo; Type=doc; Version=; Datim=19990323101500; Attrib=UUU; Recsize=0; Filesize=1254"

Note: the semicolon characters are actually GOLD semicolon subfield separators.

interrupt(2,"c:\projects\hr\doc")
returns the name of the lowest sub-directory in the specified path name i.e. doc

interrupt(5)
returns the name of the current directory e.g. c:\projects\hr\doc\

interrupt(6,"sub_dir")
tags the specified directory name onto the end of the current directory name e.g. c:\projects\hr\doc\sub_dir\

interrupt(7,"c:\projects\hr\doc")
returns the parent directory of the specified directory i.e. c:\projects\hr\

interrupt(10)
returns a list of the files in the current directory e.g. memo.doc;tax.xls;car.xls

interrupt(10,"*.xls")
returns a list of the files in the current directory that match the specified profile e.g. tax.xls;car.xls

interrupt(11,"c:\projects\hr\")
returns a list of the directories immediately below the specified directory e.g. doc;txt;ppt

The values returned in $status by the interrupt proc statement are 0 for successful or –1 for failed e.g. file does not exist.

Note this is an undocumented feature, so use with caution, it has been tested on a Windows Networking environment, but not other environments such as Netware.

compuware_01.gif (3977 bytes)


Copyright ©2000 OCS Consulting plc

dbs_block_logo.gif (2150 bytes)
Refresh Frames