Directives
PREFIX Set File Search Rules
   
Formats
1. Set Prefix 0 (Zero): PREFIX [search_string$]
2. Set Any Prefix Number: PREFIX (num)[search_string$]
3. Set Program Retrieval Rules: PREFIX PROGRAM [search_string$]
4. Specify Search Rules in Keyed File: PREFIX FILE [filename$]
5. Define virtual directory: PREFIX DIRECTORY dirpfx$ = dirpath$

Where:

filename Name of a variable-length Keyed file containing data records that define the locations of specific files (in effect, a lookup or translation table).
num Numeric value between 0 (zero) and 9 which defines the PREFIX
entry to use. If you omit this value, the default is zero.
search_string$ One or more pathname prefixes (search locations) you want ProvideX to search when attempting to find files / programs. Optional string expression.

Use a null string, PREFIX [(num)]"", or omit the string, PREFIX [(num)]) to have ProvideX remove a PREFIX.

When you have more than one search location in a PREFIX directive, the different locations must be space-separated. If you need to include a space within a directory name, then that directory location must be enclosed in double quotation marks; e.g.,

PREFIX "C:\Tmp\C:\Usr\""C:\rogram Files\"""

dirpfx$ The logical directory prefix that the program will use when referencing files
dirpath The target actual directory to be used when using Virtual Directories
   
Description Use the PREFIX directive to define a series of search paths to be inserted in front of all relative file references used in OPEN / LOAD / RUN / CALL / PERFORM directives. (ProvideX opens files with absolute paths directly, without performing a search.)
Each prefix can contain 0 (zero) or more search locations. (A search location is either a directory or a disk/directory pair.) You can specify up to 10 differently-numbered prefixes (i.e., PREFIX(0) through PREFIX(9)) as well as a PREFIX PROGRAM and a PREFIX FILE. See the descriptions of the various formats, below.
   
See Also ProvideX Search Rules,
Equal Signs for Matching,
Asterisks as PREFIX Wildcards,
ProvideX Search Rules
Using the PREFIX Directive in the ProvideX User's Guide.
   
Format 1 Set Prefix 0 (Zero)

PREFIX [search_string$]

If no numbered prefix is specified, then the PREFIX command affects PREFIX(0) by default. For example, PREFIX "C:\TMP"would apply to PREFIX(0).

   
Format 2 Set Any Prefix Number

PREFIX (num)[search_string$]

Use this format to define a maximum of 10 numbered prefix table entries (range 0 to 9) to set file search rules. Each table entry can contain multiple paths; e.g.,

PREFIX (4)"PGMS\CST\CASHRCPT\\PGMS\MGMT\MISC\ \PGMS\SALES\"

   
Format 3 Set Program Retrieval Rules

PREFIX PROGRAM [search_string$]

Use the PREFIX PROGRAM format to define the search location(s) ProvideX will search first when it attempts to LOAD/RUN/CALL/PERFORM/SAVE programs; e.g.,

PREFIX PROGRAM "\other\pgm\tst\"

If you omit the prefix string or use a null string (PREFIX PROGRAM ""), ProvideX will reset the program prefix to null.

   
Format 4 Using Paths in Keyed File

PREFIX FILE [filename$]

Use the PREFIX FILE format to specify the special Keyed file that contains information to be used for dynamic translations of files when they are opened in your applications. Any file you define as a PREFIX FILE must be a variable-length Keyed file or ProvideX returns Error #17: Invalid file type or contents.

If you define a PREFIX FILE, then ProvideX searches this special Keyed file for a search location whenever it encounters an OPEN command with a relative filename, using filename$ as the key to the PREFIX FILE. (Remember that ProvideX opens filenames with absolute paths directly, without performing a search.) Normal PREFIX search rules still apply after a filename has been located in the PREFIX FILE.

When you write to this special Keyed file, treat the filename from your program's OPEN command as the Key. The data record for each key contains the true filename you want opened instead. (ProvideX retrieves the data record internally with a READ RECORD.)

KEYED "someloc.dat",25
OPEN(chan)"someloc.dat"
WRITE RECORD(chan,key="myfile")"c:\tmp\myfile" CLOSE(chan)
.....
PREFIX FILE "someloc.dat"
OPEN(chan)"myfile ! Internally this becomes OPEN(chan)"c:\tmp\yfile" instead

The return value from the Function PFX(-1) can be used to determine if a PREFIX FILE is set and what its pathname is.

 
PREFIX FILE record layout:

The PREFIX FILE is defined as a keyed file with a primary/external key equal to the largest filename that your application will use. The first field in this file will contain the real pathname to be accessed and the second field the option OPT= option value to be used during the open. Any options specified in this second field will be added to any options specified on the OPEN.

In PxPlus (as of build 9182) a third field may be specified that contains the IOLIST to use, when opening the file with an IOL=* option. In addition, when using PxPlus, if the pathname (the first field) is empty in the PREFIX FILE record, the original file name will be used allowing the PREFIX FILE to add only the open options and IOLIST.

   
ProvideX Search Rules The ProvideX default is to search all prefixes, in the following order:
OPEN Directive LOAD/RUN/CALL/PERFORM/SAVE Directives
1. PREFIX FILE, if set; replaces pathname then continues sequence. 1. PREFIX FILE, if set; replaces pathname then continues sequence.
  2. Program Cache.
2. Current Directory; if 'CD' system parameter is set. 3. Current Directory; if 'CD' system parameter is set.
3. PREFIX 0 to 9. 4. PREFIX PROGRAM if set.
4. PREFIX PROGRAM, if set. 5. PREFIX 0 to 9
5. Current Directory; if 'CD' system parameter not set. 6. Current Directory; if 'CD' systemparameter not set.
  The PREFIX search rules apply not only to files being found, but also to files being created.

ProvideX creates files in the first location that is permitted by the PREFIX rules. If 'CD' (Search Current Directory) is on, then all files are created in the current directory (the first permitted location). If the 'CD' system parameter is off, then ProvideX creates the file in the first location permitted by the search rules above. Windows search rules are used to find DLLs (i.e., not PREFIX search rules or current directory).

Use the ENABLE and DISABLE directives to control which of the numbered prefixes ProvideX will use in the search. (While scanning prefixes 0 to 9, ProvideX ignores any prefix that is disabled.)

Note that the initial check for PROGRAM cache checks for a match against the original filenames. Thus, if you used CALL"ABCD" and you had previously loaded a program with the same name, ProvideX would use the one in cache. This eliminates the directory searches involved, but if you have duplicate program names in your system, it is possible to get the wrong one, for instance, if you CALL"ABCD", change the directory / prefix, then re-CALL"ABCD". If this happens for duplicate program names in your system, either clear the cache or do not use it.

For more information, refer to DISABLE Disable Use of Prefix Table Entry, ENABLE Re-Enable Use of Prefix Table Entry, and the 'CD' System Parameter.

   
Equal Signs for Matching Equal signs in a PREFIX search string have special meaning. Each character of the filename that corresponds by position to an equals sign will be used to form a subdirectory name to be used in the search. For instance, if you include 1 equals sign, ProvideX will interpret that to mean that the first character of filename$ is also the subdirectory name. If you include 2 equals signs, it will take the first 2 characters as matching the subdirectory name, and so on.

ProvideX automatically finds the location to retrieve or create files by looking first for a subdirectory with a name matching, character-by-character, in sequence, the portion of the filename that corresponds to the equals signs. This allows you to sort files into subdirectories based on automated substitution of the first few characters of your filename, and accelerates the search for and/or creation and saving of files in subdirectories.

Example:

PREFIX (4)"C:\MYAPP\==\ ...

If a directory entry in a PREFIX contains equals signs as shown in the example above, ProvideX evaluates the initial two characters as matching characters and uses them as the name of the subdirectory where the search will commence for relative file references. In the following example:
PREFIX "C:\MYAPP\==\" OPEN (1)"ARHIST"
ProvideX evaluates the filename ARHIST as C:\MYAPP\AR\ARHIST for purposes of the initial search.

   
Asterisks as PREFIX Wildcards You can also use * and ** as wildcard characters to support the use of filename extensions without modifying your code. This feature was added to the ProvideX language as of Version 4.20 primarily for Windows 2000 users, since the Microsoft Certification rules for Windows 2000 require that all files have file extensions. With the wildcard characters, you can rename files on disk with a common file extension without modifying the program code.

Using a Single Asterisk (*)

If the PREFIX directive includes an asterisk plus a specified extension as a filename, ProvideX inserts the filename from your OPEN command in place of the asterisk and searches first for the filename with the extension you specify in the prefix; e.g.,

PREFIX "c:\somedir\*.PRG"
OPEN(chan)"FOOFOO"

ProvideX will scan the disk for "c:\somedir\FOOFOO.PRG" and open that file if found. If FOOFOO.PRG is not found, ProvideX will attempt to find and open a file named "FOOFOO".

Using Two Asterisks (**):

If the PREFIX directive includes two asterisks plus a specified extension as a filename, the substitution described above for a single star will occur only if your OPEN directive includes a simple filename (i.e., a filename without an extension). If your filename is complex (e.g., MY_FILE.DAT), no substitution occurs; e.g.,

PREFIX "c:\somedir\**.PRG"
OPEN(chan)"FOOFOO"
OPEN(nahc)"MyFile.Dat"

Since OPEN (chan)"FOOFOO" contains a simple filename, ProvideX will look first for "c:\somedir\FOOFOO.PRG", then, if not found, for "FOOFOO". Since MyFile.Dat is a complex filename and two stars are used in the PREFIX filename, ProvideX doesn't add a .PRG extension to MyFile.Dat when it executes the search to find and open the file.

   
Format 5 Virtual Directories

PREFIX DIRECTORY dirpfx$ = dirpath$

Use the above PREFIX DIRECTORY format to define virtual directories within your PxPlus system. When the system is parsing pathnames, it will compare the pathname specified by the program with all the Virtual directory names specified in the PREFIX DIRECTORY directive. If a match is found, the system will replace the directory name with the value specified in dirpath$.

For Example, if you issued the directive:

PREFIX DIRECTORY "*usr" = "/user/mike"

Any reference to "*usr/" would reference the directory "/user/mike". So accessing a file "*usr/tempdata" would actually reference "/user/mike/tempdata".

If desired the dirpfx$ may consist of "*/name..." in which case any pathname that ends with name... will be replaced with the value in dirpath$. (This option was added in build 9190)



*Note* If the directory specified in dirpath$ does not exist, the system will create it upon first reference.