Relative Path Issue

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
ac11ca
Posts: 41
Joined: Sun Mar 16, 2008 2:22 am

Relative Path Issue

Post by ac11ca » Sat Apr 25, 2009 5:50 am

Ive read the manual and comments on this forum, but I cannot figure where I am going wrong with this coding .... help would be appreciated. Ive got a text file I want to open. The text file is located in the same folder as where my stack is being saved. So, when I command:

Code: Select all

put the filename of this stack into fld "Field" 
...I get: H:/Documents and Settings/adrian/Desktop/Methods/Game/Exp5 (v1.6).rev. Perfect, so I can call up my text file with:

Code: Select all

put url("file:" & "H:/Documents and Settings/adrian/Desktop/Methods/Game/sample1.txt") into fld "Field"
...I get what I want. However, I need this to be a relative path because I will be moving the program to other compters. Since the stack and text file are both in the same folder, I think the relative path to is:

Code: Select all

put url("file:" & "sample1.txt") into fld "Field"
... but that doesnt work >.< What am I doing wrong?

Thanks for any help,
Adrian

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Post by Janschenkel » Sat Apr 25, 2009 6:36 am

When you use a relative path, Revolution will look for it on the basis of the content of the defaultFolder global property. You can both get and set this property from a script - its default value is the folder containing the executable. Also, make sure to use the effective filename of the stack or your code won't work when it's in a substack.

Code: Select all

put the effective filename of this stack into thePath
set the itemDelimiter to slash
delete the last item of thePath
put the defaultDirectory into theOldPath
set the defaultDirectory to thePath
put URL("file:sample.txt") ino field 1
set the defaultDirectory to theOldPath
This gets boring after a while, so here's an alternative that doesn't modify the defaultDirectory.

Code: Select all

put the effective filename of this stack into thePath
set the itemDelimiter to slash
put "sample.txt" into the last item of thePath
put URL("file:" & thePath) into field 1
HTH,

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

ac11ca
Posts: 41
Joined: Sun Mar 16, 2008 2:22 am

Post by ac11ca » Sat Apr 25, 2009 8:28 am

Thanks Jan; it now works like a charm. :)

Post Reply