Ah k.. well on the server side the code should be relatively simple.

You need to check for the existence of a folder, so in your .lc script --
if there is not a folder "foldername" then... applies still. If its not
there, create it (create folder "foldername")  If it wasn't there it is
now, so either way you can continue on.

I have the habit of setting the folder I wish to write to, so you could set
the folder to your existing or newly created folder.

The next question is.. If you will simply be appending a line to the file
each time, its easy enough to do so without reading in the contents of the
file.
Just put the new line after url "file:yourfilename" and you're done.

If you need to do other things to the contents first though....

if there is a file "yourfilename" then
   put url "file: yourfilename" into tVar
   do your processing of the existing data, and modify as needed with the
new information
   put tVar into url "file:yourfilename" -- to overwrite the file with the
processed data
else
   process only the new data
   put tData into url "file:yourfilename" -- to create a new file and put
the first values into it
end if

From your description the problem is very linear and should be simple to
code.



On Mon, Sep 19, 2016 at 2:15 PM, Graham Samuel <livf...@mac.com> wrote:

> Mike, thanks for that. I think I have not really explained enough about
> what I want.
>
> I have a .lc script on the server that invokes Jacque Gay’s Zygodact
> product to generate license codes, which are then passed on to the payment
> processor. This works fine. However when a code is generated, it would be
> prudent to keep it in a file which is on the server. So I want to add a few
> lines of code to the aforesaid .lc script so that each code goes into a
> text file. I don’t need a database since the list will probably be less
> than 1K lines (if it gets any bigger, I can create another solution). So
> none of this activity is taking place outside the server - it’s all
> happening in a .lc script run by the LC Server engine.
>
> In these circumstances, I thought a fairly straightforward bit of LiveCode
> coding would do the job. This is different from what you’re suggesting, I
> think - though I am out of my comfort zone doing this at all.
>
> Can I appeal for more help on this?
>
> Thanks
>
> Graham
>
> > On 19 Sep 2016, at 17:53, Mike Bonner <bonnm...@gmail.com> wrote:
> >
> > It sounds like you have an app that you want to use to manipulate files
> and
> > folders on a remote server. You could set up a script on the server as a
> > middle man pretty easily I think..
> >
> > Something like this.. (off the top of my head)
> >
> > Have it accept $_POST data, one item of which could be cmd=folder_exists,
> > and pass in the folder name to check..
> >
> > switch $_POST["cmd"]
> > case "folder_exists"
> >    if there is not a folder $_POST["folder_name"] then
> >        create folder $_POST["folder_name"]
> >        put "Folder " & $_POST["folder_name"] & "created"
> >    else
> >        put "Folder " & $_POST["folder_name"] & "Exists"
> >    end if
> > break
> >
> > case "retrieve_file"
> >    put URL ("file:" & $_POST["file_to_retrieve"])
> > break
> > case "update_file"
> >   put $_POST["new_data"] into URL ("file:" & $_POST["file_to_update"])
> > break
> > default
> >   put "invalid request"
> > end switch
> >
> >
> > No thoughts about security on this, just a barebones idea..
> >
> > Now, for the curiosity question.. Would a database back end work better
> for
> > this?  (You'd still need an intermediary script)
> >
> > On Mon, Sep 19, 2016 at 8:40 AM, Graham Samuel <livf...@mac.com> wrote:
> >
> >> I have some server space and a domain name, let’s say ‘mysite.com <
> >> http://mysite.com/>’. On this host I have a web site (www.mysite.com <
> >> http://www.mysite.com/>), plus LiveCode Server (8.1 commercial as it
> >> happens) and some scripts etc. So far, so good. Now I want to write a
> >> script that runs on the server and does the following - this is not
> code,
> >> but is supposed to show what I want to code:
> >>
> >> 1. If there is not a folder within my space called ‘myUsefulData’, then
> >> create such a folder;
> >>
> >> 2. If there is not a text file ‘myCurrentData.txt’  within the above
> >> folder, then create one (this may not be necessary, as an attempt to
> access
> >> the file might create it?);
> >>
> >> 3. Read the contents of the file into a variable;
> >>
> >> 4. Add some data from within the program (let’s say an extra line at the
> >> end);
> >>
> >> 5. Rewrite the updated file.
> >>
> >> There may also be error checking etc.
> >>
> >> Although this seems extremely simple, I find I don’t know how to do it,
> >> and so far the LC examples I’ve read don’t seem to help. I am not sure
> for
> >> example if FTP comes into the equation (I think it does) or the user
> name
> >> and password I need for FTP access from outside the server (surely
> not?),
> >> or indeed what the path to my own bit of the server actually is. Of
> course
> >> I’ve tried stuff, but nothing has worked so far, and a test script
> (running
> >> in the IDE, not within a server script) fails silently. Nothing is
> created,
> >> nothing is destroyed, but sadly everything isn’t transformed.
> >>
> >> Can anyone explain how to do this, or at least point me to an
> explanation.
> >>
> >> Sorry for the dumb question, but there it is.
> >>
> >> Graham
> >>
> >> _______________________________________________
> >> use-livecode mailing list
> >> use-livecode@lists.runrev.com
> >> Please visit this url to subscribe, unsubscribe and manage your
> >> subscription preferences:
> >> http://lists.runrev.com/mailman/listinfo/use-livecode
> > _______________________________________________
> > use-livecode mailing list
> > use-livecode@lists.runrev.com
> > Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> > http://lists.runrev.com/mailman/listinfo/use-livecode
>
>
> _______________________________________________
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Reply via email to