tips
[Top] [All Lists]

REALbasic Tip: Keeping your path names cross platform

To: "REALbasic Tips" <realbasic-tips at lists dot realsoftware dot com>
Subject: REALbasic Tip: Keeping your path names cross platform
From: Geoff Perlman <geoff at realsoftware dot com>
Date: Thu, 22 Mar 2001 12:01:04 -0600
When building a cross platform application in REALbasic that accesses files, you have to consider that the Mac OS and Windows use different characters to separate volumes, directories and filenames in a path. This is important to keep in mind when using the GetFolderItem method (which requires a pathname)
or when using the AbsolutePath property of the Folderitem class (which
contains the full path to the item.

One thing you can do to make using GetFolderItem a bit easier is to add a Separator property to your application class and in its Open event assign the correct separator based on the platform your app is compiled for. You
can then use that Separator property when calling GetFolderItem.

Another cross platform method for getting a folderitem is to use the Volume
function and the Child method of the folderitem class. This avoids the
separator issue completely. For example, to get a folderitem for Microsoft
Word in the Applications folder on the boot volume, you could use the
following line of code:

Dim f as folderitem
F = Volume(0).child("Applications").child("Microsoft Word")

And what about Mac OS X? Mac OS X is based on BSD Unix which uses "/" as the
separator. However, because REALbasic and all applications made with
REALbasic are Carbon applications on Mac OS X, they continue to use ":" as
the separator. The one exception is when accessing files via the Shell
class. In this case, you would use the same separator that you use on the
command line.
--

Geoff Perlman
President & CEO
REAL Software, Inc.
http://www.realsoftware.com
mailto:geoff at realsoftware dot com
Phone: 512-263-1233 x711
Fax:   512-263-1441


 - - - - - - - - - -
Got a useful tip to share? Send it to us at:
REALbasic-tips at lists dot realsoftware dot com dot
For list commands, send "Help" in the body of a message to
<requests at lists dot realsoftware dot com>


<Prev in Thread] Current Thread [Next in Thread>
  • REALbasic Tip: Keeping your path names cross platform, Geoff Perlman <=