Using Variables To Create Pathnames

There are many place where you can use a path to tell Opus where to look for a file when the publicaiton is being run.

The Launch File action includes the path to the file you want to launch.

The Read and Write actions and the Report File actions in the Storage category contain a Filename field. This field is used to enter the pathname of the file you want to create or read information from.

It is important to remember that when distributing your file the path might be different to the one you are using to create the publication and this should be taken into account. Which is why we allow paths to include variables which can be set to specify a location specific to the user’s computer (see 2: below)

Opus provides four different ways of entering the pathname to this field, they are as follows:

1. Type in the pathname of the text file:

image\Variable_Pathnames_1.jpg

This is the simplest method however you can also use the Browse and find the folder where the file is stored.

2. Use the SYSTEM_PUBLICATION_DIR or SYSTEM_TEMP_DIR system variables.

image\Variable_Pathnames_2.jpg

The SYSTEM_PUBLICATION_DIR variable contains the pathname where your publication is located when it is published – the file will be stored in this path.

The SYSTEM_TEMP_DIR variable contains the pathname of the Windows Temp directory – the file will be stored in this directory.

The SYSTEM_PROGRAMAPPDATA_DIR

Using this method you do not have to literally type in a pathname, Opus will work out where to place the file. This is particularly useful if the user installs your publication in a different location than you originally intended. But remember if the original file is to be distributed with Opus you will need to do this yourself.

Note:
If the publication is run via a CD-ROM do not use the SYSTEM_PUBLICATION_DIR variable because the file cannot be written to a CD-ROM. Use the SYSTEM_TEMP_DIR variable instead.

The backslash ( \ ) must be included between folder names and the filename. It is important to include the chevrons (i.e. < >) at the beginning and end of the variable name.

3. Use your own user-defined variables.

image\Variable_Pathnames_2.jpg

This method allows you great flexibility. In the illustration above, <studentCourse> is a user-defined variable this can equate to any pathname, e.g. A:\History or C:\Arts\History, etc. The <stuName> variable can be the name of the student taking the course and the information is written and read from the data.txt file.

This means you can have several students take a variety of courses and the results of all courses are stored in separate files (all with the same filename but in different folders and under different courses and student name). The variables can be filled-in using the Set Variable action e.g. you could ask the user to enter their name which is saved in <stuName> and then select a course from a list provided, which is saved in <studentCourse>.

Note:
The backslash ( \ ) must be included between folder names and the filename. It is important to include the chevrons (i.e. < >) at the beginning and end of the variable name.

4. Type in an Alias name option in the Additional Resources tab of the Publication Properties dialog.

image\Variable_Pathnames_3.jpg

An alias name is a shortcut method of referring to a file in your publication. In the illustration above studentResults is an alias name for c:\studentResults\results.txt – this could be used to store each student’s exam results.

Alternatively, you could create several alias names for different files and enter a variable (e.g. <whichCourse>) in the Filename field – the variable would contain one of the alias names.

Related Topics:

Introducing the Storage Actions

Restrictions Reading and Writing Disk Files

Disk Files vs Windows Registry

the Set Variable action

the Additional Resources tab