Relative file path

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

Leff
Posts: 26
Joined: Sun Sep 21, 2014 12:44 pm

Relative file path

Post by Leff » Sat Oct 04, 2014 8:00 pm

What is the code (path) to the relative file/folders path within the livecode project I'm making?

If my new app is in a folder called "test" and have sub folders called "/audio" and "/images" how do i accsess them with a relative path?

I made a button with:
on mouseUp
put the folders
end mouseUp

It also shows files that are not in the "test" folder where my app is.

This did not help:

set the itemDelimiter to "/"
get the effective fileName of this stack
set the defaultFolder to item 1 to -2 of it

Been googling but did not find what to do :-)

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Relative file path

Post by Mark » Sat Oct 04, 2014 9:09 pm

Hi,

To make sure that you find your own app, you can do this:

Code: Select all

set the itemDel to slash
put item 1 to -2 of the effective filename of this stack into myPath
set the defaultFolder to myPath
put the folders & cr & the files
(folders doesn't show files)

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Leff
Posts: 26
Joined: Sun Sep 21, 2014 12:44 pm

Re: Relative file path

Post by Leff » Sat Oct 04, 2014 9:26 pm

I put that in the Stack Script. Is that where its going to be?

And if the folder where the app and subfolders are what url will it be?

Like this:?
on mouseUp
set the filename of player "Player" to "../Audio/test.mp3"
end mouseUp

This dont work.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Relative file path

Post by Mark » Sat Oct 04, 2014 10:29 pm

Hi,

Why do you think that you have to put that into the stack script? It is the code that you need to get to the location of your app or stack. Use it in whatever handler you want to use it in.

Probably you should read chapter 5 of the user manual or chapter 2 of my book. You need to understand the basics before you start making a real app. It is also a good idea to look up the concept of message hierarchy; here's a lesson that explain it briefly.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Leff
Posts: 26
Joined: Sun Sep 21, 2014 12:44 pm

Re: Relative file path

Post by Leff » Sat Oct 04, 2014 10:56 pm

Hi.

The reason for thinking that is because I don't know. Thats why I write here at Complete Beginners!
There will be no real app at this point. I am playing around with LiveCode as many has suggested.

It was an easy question. The relative path...? So if I make a folder on my desktop and name it "Test" and save a LC project there and put my subfolders (audio, video and so on in it) I would like to use a relative path instead of a real path. Just to se if everything is following when saving as a standalone app. I dont want to use sub stack for all the audio /video files I am going to use. A small app with big folders.

So...

Lets say I want a button to play with "player" a mp3 file stored in /Test/Audio/test.mp3 what will the relative path be?
I have been trying:

on mouseUp
set the filename of player "Player" to "/Test/Audio/test.mp3"
end mouseUp

That dont work... also "./Audio/test.mp3" and so on... no luck yet.
If there is an answer to that I would be happy to have it :)

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Relative file path

Post by Mark » Sat Oct 04, 2014 11:13 pm

Hi,

If you run the script I gave you in e.g. a mouseUp handler, you'll get a little more insight in what you get when you use relative paths.

Relative paths work if your stack actually has a path. Perhaps saving your stack makes a difference. if you use the inspector to set the path, you should get a relative path by default, but only if your stack is saved, i.e. if exists on disk and has an actual file path. These relative file paths are of the format ./filename.xyz or ./folder/filename.xyz.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Leff
Posts: 26
Joined: Sun Sep 21, 2014 12:44 pm

Re: Relative file path

Post by Leff » Sat Oct 04, 2014 11:18 pm

Thank you!

Going to try a bit more based on that information. The project was saved.

Leff
Posts: 26
Joined: Sun Sep 21, 2014 12:44 pm

Re: Relative file path

Post by Leff » Sat Oct 04, 2014 11:29 pm

Deletet the old installation (7 rc) Installed the LC 6.6.2

Did the same thing as before and now it works...

on mouseUp
set the filename of player "Player" to "/Audio/test.mp3"
end mouseUp

It is good to know that it was not me but the installation of LC 7

Now I can actually do something with LC. Fun :) To bad I used several hours with a program that did not work.

newtronsols
Posts: 192
Joined: Tue Mar 11, 2014 12:57 pm

Re: Relative file path

Post by newtronsols » Sun Oct 05, 2014 4:18 pm

It is a curious thing but I thought iterative (agile) design meant that each test/build things got better. So I'd imagine 6.7 was everything 6.6 plus a bit more. But I read the forum 'suggest' that e.g. 6.x commercial isn't 6.x community or that 7 [potentially/ I don't know] could be stable 6.5 'forked off' to 7. I only suggest this as 7 exports to 6.5 - not a later build.

It is a nightmare to dev something one day that works in 6.5 but then doesn't in 6.6 and then works again in 6.7 but not 7. You imagine it must be 'your fault' so you waste days searching for accidental extra spaces etc - when all along it was a random difference between a past and future version. If I had an employer asking me to do this I would have been sacked - he would have thought I was doing something seriously wrong with Livecode at each release.

I really don't know how anyone can manage such a development roadmap and know what works/what doesn't in each version. A lot of excellent/expensive fixes must get lost and replaced with an inferior fix.

Hopefully a complete regression test will occur one day so everything that was fixed gets re-tested and the fix re-put back from a previous better working version.

Leff
Posts: 26
Joined: Sun Sep 21, 2014 12:44 pm

Re: Relative file path

Post by Leff » Sun Oct 05, 2014 8:34 pm

I started with the 7x rc and did not think about that it's not stable... Hopefully 6.6.3 is the right one :)

I have some more things I don't understand...

When saving as a standalone app (including the subfolders with my images and audio files) things don't go as it should. Must be me.

On my osx-pc the app looks like it should but not all the files (some images are not imported even though the subfolder are selected) are imported. Maybe LC only import files that are active in my project?
On my windows-pc the app did not look as it should. The background should be white, but was grey. The pictures did not show and the audio player was not displayed at all and off cource no audio. Strange.

Things I really should learn now is: How to make fields, buttons, image, and so on stay at their place relative to the window-edges when resizing the app. Have tried a bit today, but no luckt yet. Let's say I will have a right object (controller field for audio and video) that stick to the right edge of the window even when resized, what code could I use?

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: Relative file path

Post by [-hh] » Sun Oct 05, 2014 8:53 pm

Hi Leff,
sounds like you didn't look at the *very* fine tutorials ? These and also a lot of other resources are reachable within the IDE: At topright, or menu View -> Toolbar Text|Icons, or use menu "Help".

I started also with the tutorials and got most first answers (like yours now mentioned) immediately from working with these. And questions based on these will be answered here, possibly by one of the authors itself.

@newtronsols
newtronsols wrote:I really don't know how anyone can manage such a development roadmap and know what works/what doesn't in each version.
The set of persons who know what works/what doesn't in each version is a perfect example for an empty set.
shiftLock happens

Leff
Posts: 26
Joined: Sun Sep 21, 2014 12:44 pm

Re: Relative file path

Post by Leff » Sun Oct 05, 2014 9:25 pm

Reading about video library right now. Maybe I can use the same procedure with audio files.

Regarding using the tutorials, I do! Tried the bottomLeft or bottomRight to check if the button would stay all the way to the right in the app when resizing (no luck yet). I do realise that I can't learn all about LC right now. It's fun trying and when I'm lost I'm asking here and googling or looking at tutorials.
Thanx for answering my questions! :)

Klaus
Posts: 14205
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Relative file path

Post by Klaus » Sun Oct 05, 2014 10:12 pm

Hi Leff,
Leff wrote:On my osx-pc the app looks like it should but not all the files (some images are not imported even though the subfolder are selected) are imported. Maybe LC only import files that are active in my project?
did you add the folders in the standalone builder on the"Copy files" tab?
Leff wrote:On my windows-pc the app did not look as it should. The background should be white, but was grey.
Yep, this happens when you do not set the background color of your stack(s) explicitly!
Set the backgroundcolor in the inspector for the stack and it will work on Mac and Windows.
Leff wrote:The pictures did not show and the audio player was not displayed at all and off cource no audio.
This sounds like a pathname problem!
Do you use relative filenames for images, videos and sounds?

Hint: You know that QuickTIme needs to be installed on the target Windows PC when you are using player objects for sounds and videos?


Best

Klaus

Leff
Posts: 26
Joined: Sun Sep 21, 2014 12:44 pm

Re: Relative file path

Post by Leff » Sun Oct 05, 2014 11:03 pm

Hi Klaus,
Klaus wrote:did you add the folders in the standalone builder on the"Copy files" tab?
Yes I did.
Klaus wrote:Set the backgroundcolor in the inspector for the stack and it will work on Mac and Windows.
Thought of it just after posting... Now it's done :-)
Leff wrote:Do you use relative filenames for images, videos and sounds?

Hint: You know that QuickTIme needs to be installed on the target Windows PC when you are using player objects for sounds and videos?
I use "./" for folders with images, videos and sound. Is that correct?
When trying to save LC only import the active image and audio file. Must be something I do wrong. Just don't know what :)

Klaus
Posts: 14205
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Relative file path

Post by Klaus » Mon Oct 06, 2014 1:59 pm

Hi Leff,
Leff wrote:I use "./" for folders with images, videos and sound. Is that correct?
when it works, it is correct :D
I just do it this way -> audio/sound.mp3 and that works, too!
Leff wrote:When trying to save LC only import the active image and audio file.
Sorry, don't understand?
Do you mean the filename is only saved with the stack in that case?
That would be correct, LC cannot read our minds (yet) :D


Best

Klaus

Post Reply