Page 1 of 1

Relative Path Issue

Posted: Sat Apr 25, 2009 5:50 am
by ac11ca
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

Posted: Sat Apr 25, 2009 6:36 am
by Janschenkel
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.

Posted: Sat Apr 25, 2009 8:28 am
by ac11ca
Thanks Jan; it now works like a charm. :)