saving file to path

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
reelstuff
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 254
Joined: Mon Apr 16, 2007 12:06 am
Contact:

saving file to path

Post by reelstuff » Wed Apr 09, 2008 4:55 pm

I have a folder path, $folder_path1 which works as expected,

I am attempting to find a way to put or save a file from a field without using the dialog box,

I looked at the docs and tried to find different way to do this,

Code: Select all

put the text of fld Field_three into URL "file:test.txt"

//but now how to get the file test.txt to go to the correct directory as //defined by
$folder_path1
If I do this,

Code: Select all

get $folder_path1
the path is stored in the variable it,
(I believe)

So I did a test to see if that were true, by using a button and field, and that does seem to be the case, now I am trying to figure out how to use the path to put or save a file directly into that dir path and of course name that file accordingly.

I could just use ask, and it does work that way but I hate to have the user go through that process over and over again, so that is why I am looking at directly moving the contents of the file into the directory path.

Any thoughts and or advice, thanks.

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

Post by Mark » Wed Apr 09, 2008 5:25 pm

Hi reelstuff,

First of all, never use the $ keyword in front of variable, unless that variable is actually an environment variable, meant to communicate with the operating system.

If here is a folder folderPath1, you can put data into a file in that folder using the following syntax:

Code: Select all

put myData into url ("file:" & folderPath1 & "/filename.txt")
Best,

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

reelstuff
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 254
Joined: Mon Apr 16, 2007 12:06 am
Contact:

Post by reelstuff » Wed Apr 09, 2008 6:20 pm

Mark wrote:Hi reelstuff,

First of all, never use the $ keyword in front of variable, unless that variable is actually an environment variable, meant to communicate with the operating system.

If here is a folder folderPath1, you can put data into a file in that folder using the following syntax:

Code: Select all

put myData into url ("file:" & folderPath1 & "/filename.txt")
Best,

Mark
BTW thanks a lot for the help and advise,


Thanks Mark, that makes sense,


here is the code I am using,

Code: Select all

on mouseUp
  -- You said that I should not use the $ in this way is that correct. 
  --I tried it both ways just to see, and the folder path is generated, with the use of the fourth line.
  -- however, the file does not end up in the folderPath1 directory location. 
  --get $folderPath1
put the text of fld Field_one into myData
put myData into URL ("file:" & folderPath1 & "/test.txt")
end mouseUp

Now, I continued testing, and when I use this code

Code: Select all

on mouseUp
 get $folderPath1
put the text of fld Field_one into myData
put myData into URL ("file:" & it & "/test.txt")
end mouseUp
It works, but I dont want to use the code in the wrong way because it might cause a problem somewhere else.

Post Reply