Defaultfolder Issue

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
vbro
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 7
Joined: Tue Mar 26, 2013 7:20 am
Contact:

Defaultfolder Issue

Post by vbro » Thu May 09, 2013 8:11 am

I added a handler to my stack that reads a number of .txt files from a folder and stores their content in an array. It uses the defaultfolder property and the files keyword to get the list of files to process. At first, the handler was working fine and producing the expected results, but then the next time I opened LiveCode it was no longer working correctly. After some debugging, it seems like defaultfolder property is not retaining the value I give it when I use the set command. I even created a new mainstack and put this code into a button...

Code: Select all

on mouseUp
   set the defaultfolder to "./data/ships/"
   put the defaultfolder into fld 1
end mouseUp
...Which should set the defaultfolder to a path relative to where the .livecode stack resides. However, when the button is pressed, the value that gets put in field 1 is "/Users/vbro/Applications". What am I missing here?

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Defaultfolder Issue

Post by jmburnod » Thu May 09, 2013 8:39 am

Hi vbro,
I understand you didn't save your stack and the defaultfolder is the path of applications folder.
You have to build the path as you want
This function return the path of the folder where is the stack or the standalone

function MainStackFolder
put the filename of this stack into rMainStackFolder
put the platform into tPlatForm
put the environment into pEnv
put the itemdel into OID
set the itemdel to "/"
put the num of items of rMainStackFolder into nbF
 if tPlatForm = "MacOS" then
if pEnv = "standalone application" then
delete item (nbF-3) to nbf of rMainStackFolder
end if
if pEnv = "development" then
delete last item of rMainStackFolder
end if
else
delete last item of rMainStackFolder
end if
set the itemdel to OID
return rMainStackFolder
end MainStackFolder

Best regards
Jean-Marc

P.S. Why "code" and "quote" buttons dont' work today ?
https://alternatic.ch

vbro
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 7
Joined: Tue Mar 26, 2013 7:20 am
Contact:

Re: Defaultfolder Issue

Post by vbro » Sat May 11, 2013 7:19 am

Thank you very much. With this handler I can now set the defaultFolder appropriately according to the environment and OS the stack is running on. I think I may have been putting malformed folder paths into defaultFolder, but I'm not sure. Either way, greatly appreciated.

Post Reply