Page 1 of 1
path to the .livecode file I'm working on
Posted: Fri May 13, 2011 5:36 am
by sp27
Section 11.1 File Name Specifications and File Paths goes to great length explaining paths and folders, but I can't find a way to get the folder where my current application is--in the development environment, not as a standalone. While I work on it, the defaultFolder tells me where LC is installed, but I want to use relative paths to the folder where my .livecode file is stored. Any Director programmer will know that I'm looking for "the moviePath"

Re: path to the .livecode file I'm working on
Posted: Fri May 13, 2011 7:26 am
by Dixie
sp27...
This will set the defaultFolder to be the folder that contains the stack on which you are working. Also, have a look at 'specialFolderPath' in the dictionary...
Code: Select all
on preOpenStack
set itemDel to "/"
set the defaultFolder to item 1 to -2 of (the effective fileName of this stack)
end preOpenStack
take care
Dixie
Re: path to the .livecode file I'm working on
Posted: Fri May 13, 2011 7:34 am
by sp27
Cool--thanks, Dixie!
Re: path to the .livecode file I'm working on
Posted: Fri May 13, 2011 2:35 pm
by FourthWorld
I've found the default folder somewhat problematic because it can be changed at any time.
So I've been using the fileName property of the stack, which will work well in both the IDE and in a standalone. Note that in a standalone on OS X it will point to the executable within the bundle, so you may want to account for that if you need to get the back to the folder the bundle is in.
Code: Select all
function StackFolder pStackName
set the itemdel to "/"
-- "effective filename" lets this work on substacks as well as mainstacks:
put the effective filename of stack pStackName into tPath
delete last item of tPath
return tPath
end StackFolder
Re: path to the .livecode file I'm working on
Posted: Sun May 29, 2011 1:00 am
by Gene
sp27 wrote:Section 11.1 File Name Specifications and File Paths goes to great length explaining paths and folders, but I can't find a way to get the folder where my current application is--in the development environment, not as a standalone. While I work on it, the defaultFolder tells me where LC is installed, but I want to use relative paths to the folder where my .livecode file is stored. Any Director programmer will know that I'm looking for "the moviePath"

Try using 'the Current Folder' the same way you used to use 'the MoviePath' in Director. I just spent half the afternoon duking it out with the correct file path syntax to get to a local html file using a relative path. The User Guide sorta gave hints, but wouldn't just come right out and say that you need to cite a full path using the Current Folder as the lead segment.
Here is an example that will give you the idea (I hope). Bottom line is that it works for me: "put revBrowserOpen(tWinID,"file:"& the current folder & "/BootsQuestion/quiz.html") into sBrowserId."
This is, of course just one line of code that also contains some variables aren't important to the topic at hand, but it contains a relative path using Current Folder the same way I would have previously used the MoviePath. The user guide sorta kinda makes out like you can create a relative path by using only the path downstream of the folder containing your authoring or standalone exectutible, but that doesn't appear to be the case. I tried everything, and had to introduce the Current Folder to give the function the full path to my html. Go ahead and type "the current folder" into the message box, and it'll kick the full path to your application right back just like the moviepath would in Director.
By the way, all of the revBrowser examples used http://, ftp://, etc. because it was assumed that you would want html from the net. I had to really dig to find out how to use "file:" in place of "http://" to get to a local file. Maybe I'm just not experienced enough to figure that out right off, but it sure didn't jump off the pages of the guide.
Re: path to the .livecode file I'm working on
Posted: Sun May 29, 2011 3:01 am
by jacque
Gene wrote:sp27 wrote: The user guide sorta kinda makes out like you can create a relative path by using only the path downstream of the folder containing your authoring or standalone exectutible, but that doesn't appear to be the case.
You can, and it is, but you have to be aware of the current directory. By the way, in case you happen to see us using different syntax, these are all synonyms:
the directory
the defaultfolder
the current folder
As RIchard mentioned, the defaultfolder (current folder, directory) can change depending on your scripts so you need to keep track of where it is if you want to use relative file paths. All relative file paths use the current folder as their base. When your standalone launches, the current folder is the one containing the standalone, but in the IDE it can change. However, when the IDE is first launched, the default folder is the one containing LiveCode.
Let's say you've just launched LiveCode and you haven't changed the folder. In that case, a file named "foo.txt" would be assumed to live in the same folder with the LiveCode program. Now let's say your scripts have set the default folder to somewhere else at some point:
Code: Select all
set the defaultfolder to specialfolderpath("desktop")
Now if you just refer to a file named "foo.txt" the engine will look for it on the desktop.
If you aren't sure what the current directory is, then providing a full path as you did is always safe. In fact, it's usually safer to just go ahead and do that anyway unless you are keeping track of locations carefully in your scripts.
Re: path to the .livecode file I'm working on
Posted: Sun May 29, 2011 7:20 am
by sp27
This is not relevant to the discussion, but please be careful when you quote other posters. Poster "sp27" would never have said "...sorta kinda makes out like you can..." It's just not his style

Re: path to the .livecode file I'm working on
Posted: Sun May 29, 2011 4:14 pm
by Gene
Sorry, sp27, I meant no offense, and I wouldn't ever put words into someone else's mouth in any case. However if you look at my original message, my quote from your message did not contain "sorta kinda." That was in the text of what I wrote, not the your original message text. Somehow, though, the
reply to my message contains a quoted section that somehow attributes the "sorta kinda" to you

I think it was due to the way the forum automatically handles quotes of quoted text. Anyway, like you said, it's off topic, and I shouldn't compound things by being defensive. I knew I was going to get myself in trouble a some point if I posted to the forum, so I guess this is was it!
I do appreciate Jacques patient explanation, though, even if I still have some questions.
Re: path to the .livecode file I'm working on
Posted: Sun May 29, 2011 5:32 pm
by jacque
Apologies, I'm pretty sure I must have trimmed the message incorrectly. I'm not quite sure how the quote ended up attributed to you, sp7, but I"ll try to keep a better watch on things.
On the other hand,
I would probably say "sorta kinda".

Re: path to the .livecode file I'm working on
Posted: Sun May 29, 2011 6:45 pm
by Gene
Thanks, Jacque. I'm a newcomer here, and I hesistate to add yet another message to this thread, but I do want say that this forum is probably the most enjoyable and useful forums I have ever participated in. Everyone is polite and respectful of one another, and the posts are meaningful and intelligent. It's a pleasure to be associated with this community. QED.
Re: path to the .livecode file I'm working on
Posted: Sun May 29, 2011 10:10 pm
by sp27
Likewise here!!!
sp27