path to the .livecode file I'm working on

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
sp27
Posts: 135
Joined: Mon May 09, 2011 3:01 pm

path to the .livecode file I'm working on

Post by sp27 » Fri May 13, 2011 5:36 am

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" :)

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: path to the .livecode file I'm working on

Post by Dixie » Fri May 13, 2011 7:26 am

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

sp27
Posts: 135
Joined: Mon May 09, 2011 3:01 pm

Re: path to the .livecode file I'm working on

Post by sp27 » Fri May 13, 2011 7:34 am

Cool--thanks, Dixie!

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: path to the .livecode file I'm working on

Post by FourthWorld » Fri May 13, 2011 2:35 pm

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
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Gene
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 75
Joined: Wed Mar 09, 2011 6:48 pm

Re: path to the .livecode file I'm working on

Post by Gene » Sun May 29, 2011 1:00 am

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.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: path to the .livecode file I'm working on

Post by jacque » Sun May 29, 2011 3:01 am

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

sp27
Posts: 135
Joined: Mon May 09, 2011 3:01 pm

Re: path to the .livecode file I'm working on

Post by sp27 » Sun May 29, 2011 7:20 am

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 :D

Gene
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 75
Joined: Wed Mar 09, 2011 6:48 pm

Re: path to the .livecode file I'm working on

Post by Gene » Sun May 29, 2011 4:14 pm

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.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: path to the .livecode file I'm working on

Post by jacque » Sun May 29, 2011 5:32 pm

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". :)
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Gene
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 75
Joined: Wed Mar 09, 2011 6:48 pm

Re: path to the .livecode file I'm working on

Post by Gene » Sun May 29, 2011 6:45 pm

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.

sp27
Posts: 135
Joined: Mon May 09, 2011 3:01 pm

Re: path to the .livecode file I'm working on

Post by sp27 » Sun May 29, 2011 10:10 pm

Likewise here!!!

sp27

Post Reply