D3 Tip – OSFI Part 1
Over the years there seems to be continuing confusion on how the D3 OSFI works, and confusion with the similarly named FSI. In this first tip on this topic, I’ll provide a couple hints about how to use slashes and drive references, and some examples for use.
Once in a while we’ll see someone post an OSFI path that looks like this: "\dir1\dir2". The actual syntax is "/dir1/dir2", always with forward slashes, regardless of OS.
There is also confusion about drive references. The syntax for a D3 path is "Host : /path". Where we see "C:/path", people tend to assume that C: is a direct reference to the C: Windows hard drive (partition), but this isn’t correct. The text before the colon, "C" in this case, is a reference to an item in the Hosts file. If you are referring to an "R:" drive, whether this is on the localhost or it is an alias for a directory on some remote system, then there must be an item in Hosts with ID "R". See the default items C, D, and E for samples, and the D3 documentation for definitions of each attribute in items in the Hosts file.
Many people assume that they should use C: as the default drive in a path. If there is any chance that you will be moving data to different environments (which is the case for VARs selling turnkey apps), I discourage the use of the C: host unless you are certain that data is always really going to reside in C:. Since some users prefer to load their data and some apps into a D or E drive, assuming C isn’t valid. If you leave that as "/folder/folder" then the path refers to the current hard drive, and not specifically to C:. That might be better but it’s not an entirely valid assumption either.
In fact, "C" doesn’t need to really refer to drive C at all, although C should point to C and I discourage changing it. The item "C" in the hosts file can point anywhere just like we can create a dict item with any name that looks at any data attribute we want. For turnkey apps it might be better to create an item in the Hosts file called HOME, just copy the C item to HOME for starters. Then if an app is deployed to an environment where C isn’t the primary drive, all you have to do is change an attribute in the HOME item and your entire app should function properly.
So how do we use these path references?
That points to the current directory in C:. When D3 is installed in C, that usually lists "C:\Program Files\D3\D3Programs"
OPEN "C:/TEMP" TO F.TEMP ELSE STOP
READ INFO FROM F.TEMP,"file.TXT" ELSE STOP
INFO<3> = "BLAH"
WRITE INFO ON F.TEMP,"file.TXT"
The carriage returns are converted to attribute marks on the Read and converted back on Write. Note that unlike some other MV DBMS platforms D3 does not require OPENSEQ to differentiate between files in the DBMS and files in the host OS.
Note this goes to the default drive, it does not hard-code C: the way the code above does. Casing for Windows platforms is not important but casing for *nix platforms is, so /tmp and /TMP are not the same – be careful when writing apps that are supposed to work cross-platforms.
I have some ideas about other topics related to OSFI but if you have specific questions about how any of this works, please feel free to e-mail me and I’ll be happy to write something up.