Specifying the Path to a File
In general, a file can be located almost anywhere. It might be in other folders on your hard drive, or even on an entirely different drive (such as a floppy disk, CD, etc.) Therefore it is usually necessary to specify the path to the file. A path merely specifies the sequence of folders you would have had to open in order to arrive at the file. The sequence of folder names are separated by backslash ( \ ) characters, and the names are case insensitive.
Specifying an Absolute Path
Whenever the path begins with a backslash character, it signifies that the path is specified relative to the root directory on the current drive. Such a path is referred to as an "absolute" path.
The SAMPLES project (in Pro-SiMPLE's Command-Line mode) contains a Micro-SiMPLE program named DUMPFILE which reads and displays the contents of the SIMPLE.AID text file located at:
\SiMPLE\L\D\S\SiMPLE.AID
The listing for the DUMPFILE program is shown below:
Pro-SiMPLE
line=""; eof=0
open a ("read \\SiMPLE\\L\\D\\S\\SiMPLE.AID")
loop: read line a (line, eof)
If (eof) close a; quit
output (line)
Go to loop
Notice (in the second line of the listing) that you must use two consecutive backslash characters ( \\ ) instead of only one ( \ ) whenever you use a text string to specify a path. [Remember, whenever a backslash character appears inside a pair of quotes it signifies that the next character is "special". Therefore a double backslash is used to generate a single backslash character in the text string.]
Specifying a Relative Path
Whenever the path does not begin with a backslash character, it signifies that the path is relative to the location of the source listing.* Such a path is referred to as an "relative" path.
For example, if you were to save the following listing as a file named "example.txt" and then run it, the program would display its own source listing in a window.
Ultra-SiMPLE []
Text data
Int eof
path = "example.txt"
command = "read "+path
handle = open file (command)
Do
read file (handle, data, eof)
If (eof) Break
Display data
Loop
close file (handle)
Using "Drag & Drop" for Reading/Writing Disk Files
Built into Ultra-SiMPLE is the Param() text function which returns the path(s) of any file(s) that are dropped onto the program's executable (".exe") icon. (Built into Pro-SiMPLE is the Param[] text array which provides a similar capability.) If more than one file is dropped, the first file's path will be returned by Param(1), the second file's path will be returned by Param(2), etc.
The following program will read and display the contents of any text file that is dropped onto the program's ".exe" icon, regardless of where that text file may be located:
Ultra-SiMPLE
Text data
Int eof
If (param(1) = "") quit
command = "read " + Param(1)
handle = open file (command)
Do
read file (handle, data, eof)
If (eof) Break
Display data
Loop
close file (handle)
(To use the above program, you must first run it in order to generate its ".exe" file. Then you can drop any text file onto the ".exe" icon.)
*When SiMPLE is used in "Drag & Drop" mode, the user's source listing is first copied into SiMPLE's "PROJECT" folder and then compiled there. After the program successfully compiles, a copy of its executable file (SIMPLE.EXE) is then copied back to the folder containing the source listing and executed there. If SiMPLE is unable to successfully copy the executable file back to the source folder, the SIMPLE.EXE file in the "PROJECT" folder is executed instead. Under these circumstances, the path to any user data files will be relative to the "PROJECT" folder and not relative to the location of the source listing. This problem happens in only a very small number of computers. But, if it does occur, there is an easy workaround:
Whenever a program is being compiled and executed in "Drag & Drop" mode, the program's first eight calling parameters will each contain an asterisk ("*") character, and the ninth calling parameter ("Param[9]" in Pro-SiMPLE, "Param(9)" in Ultra-SiMPLE) will indicate the path to the folder containing the program's source listing. If the program is not being compiled and executed in "Drag & Drop" mode, all of these parameters will be null characters.
Therefore, if you are experiencing problems accessing your data files from programs that are being compiled and executed in "Drag & Drop" mode, just remember to always incorporate the program's ninth calling parameter when specifying the paths to your data files. You will then always be able to access them correctly, regardless of which of the two executable files is being executed. For example, in our previous "example.txt" listing, all you would have to do is change the fourth line of the listing to:
path=Param(9)+"example.txt"