Page 1 of 2
Creating a text file isn't working for me
Posted: Mon Mar 08, 2021 3:21 pm
by trags3
Hi again,
I have worked on this for hours now and cannot find what I am doing wrong.
Code: Select all
on openStack
set the defaultFolder to (specialFolderPath("Documents") & slash)
put URL("file:" & (specialFolderPath("Documents") & "/PC.txt")) into tfile
end openStack
This code works on iPhone. only difference is I used lowercase documents rather than Documents.
I have tried both ways on my Mac.
The PC.txt file is not created.
Any suggestions?
Tom
Re: Creating a text file isn't working for me
Posted: Mon Mar 08, 2021 3:27 pm
by bogs
on openStack
set the defaultFolder to (specialFolderPath("Documents") & slash)
put URL("file:" & (specialFolderPath("Documents") & "/PC.txt")) into tfile
end openStack
Problem I see is that you have a slash, then include the slash in the files name. Me, I just include the slash as part of the name since I find it easier.
Re: Creating a text file isn't working for me
Posted: Mon Mar 08, 2021 3:38 pm
by glenn9
Not sure if its of any help but this seems to work for me...
Code: Select all
...
-- opening a file
set the defaultfolder to specialfolderpath("desktop")
put URL ("file:example.txt") into tSomething
...
-- saving a file
set the defaultfolder to specialfolderpath("desktop")
put tSomething into url ("file:example.txt")
...
Re: Creating a text file isn't working for me
Posted: Mon Mar 08, 2021 3:47 pm
by trags3
Thanks bogs but....
Code: Select all
on openStack
set the defaultFolder to (specialFolderPath("Documents") )
put URL("file:" & (specialFolderPath("Documents") & "/PC.txt")) into tfile
end openStack
THis doesn't work either.
Tom
Re: Creating a text file isn't working for me
Posted: Mon Mar 08, 2021 3:56 pm
by bogs
trags3 wrote: ↑Mon Mar 08, 2021 3:47 pm
set the defaultFolder to (specialFolderPath("Documents") )
Try dropping the outer parenthesis around specialFolder hee hee.
set the defaultFolder to specialFolderPath("Documents")
Re: Creating a text file isn't working for me
Posted: Mon Mar 08, 2021 4:21 pm
by Klaus
Hi Tom,
you are supplying an ABSOLUTE pathname, so setting the defaultfolder is not neccessary!
Try this:
Code: Select all
on openStack
put specialFolderPath("documents") & "/PC.txt") into tfile
if there is NOT a file tFile then
answer "Not file yet!"
else
put url("file:" & tFile) into fld "content of file"
end if
end openStack
Best
Klaus
Re: Creating a text file isn't working for me
Posted: Mon Mar 08, 2021 4:27 pm
by Klaus
To be clear, THIS:
Code: Select all
put URL("file:" & (specialFolderPath("Documents") & "/PC.txt")) into tFile
will NOT create a file, but rather read that file into the variable tFile or give an ERROR if the file is not present!
Re: Creating a text file isn't working for me
Posted: Mon Mar 08, 2021 4:30 pm
by bogs
I must be slow this morning, forgive me. Let's start over here with your initial statement (now that I actually read the title of the post).
Creating a text file isn't working for me
So, everything I said about the default folder isn't going to create a file, to do that, you need 2 things, a path, which is what your building tFile to be, and something to put INTO that path.
This code puts the contents of an existing file into a variable :
put URL("file:" & (specialFolderPath("Documents") & "/PC.txt"))
into tfile
To put that variable (or whatever) back into a file, you need to reverse it:
put tfile into URL("file:" & (specialFolderPath("Documents") & "/PC.txt"))
NOW that we're on the same page, are there any other questions hee hee.
LOL I see Klaus beat me too it
Re: Creating a text file isn't working for me
Posted: Mon Mar 08, 2021 5:38 pm
by trags3
Klaus
This doesn't work.
You are missing a "(" somewhere I put it after the "&" didn't work
I removed the ")" before the into and that didn't work
I put it in front of "special and that doesn't work either
Code: Select all
on openStack
put specialFolderPath("documents") & "/PC.txt") into tfile
if there is NOT a file tFile then
answer "Not file yet!"
else
put url("file:" & tFile) into fld "content of file"
end if
end openStack
I am using LC 9.6.1
Macbook air OS Catalina 10.15.4
Tom
Re: Creating a text file isn't working for me
Posted: Mon Mar 08, 2021 5:52 pm
by Klaus
Hi Tom,
yes, sorry for the "(":
Code: Select all
...
## This is correct:
put specialFolderPath("documents") & "/PC.txt" into tFile
...
But what do you mean with ->
This doesn't work?
Do you see the dialog in LC?
Do you see the content of that file in your field?
Did your machine explode?
Or what do you think SHOULD happen but didn't?
Best
Klaus
Re: Creating a text file isn't working for me
Posted: Mon Mar 08, 2021 6:30 pm
by trags3
It still does not work.
There is not a file named PC.txt anywhere on my computer.
Tom
Re: Creating a text file isn't working for me
Posted: Mon Mar 08, 2021 6:38 pm
by Klaus
Just to be sure:
specialfolderpath("documents") on desktop is completely different from specialfolderpath("documents") on MOBILE!
They are NOT the same folders! They have nothing in common except the name and the fact that we have write permission
in that folder on desktop and mobile.
Re: Creating a text file isn't working for me
Posted: Mon Mar 08, 2021 6:57 pm
by trags3
This app isn't going to be on mobile.
Tom
Re: Creating a text file isn't working for me
Posted: Mon Mar 08, 2021 7:16 pm
by Klaus
Hi Tom,
well, someone needs to write that file to your specialfolderpaht("documents") before you can load it into your stack!
Did you? If yes, how? If not, who on earth did?
This does NOT create a file:
Code: Select all
on openStack
put URL("file:" & (specialFolderPath("Documents") & "/PC.txt")) into tfile
end openStack
Best
Klaus
Re: Creating a text file isn't working for me
Posted: Mon Mar 08, 2021 7:35 pm
by trags3
Hi Klaus
I guess I'm trying to do something that maybe can't be done.
When the app is sent to a user I was under the impression that the app would be able to generate about 9 or 10 empty txt files that will be used when the app is running. As they enter data on a card it is saved in a field on the card. When they skip to the next card the data in the fields get saved in a text file. If the user quits the app before completing all pages of input, those files are used to repopulate the cards with the data they had entered during the prior use of the app.
Is there an easier way to accomplish this? I have done this on other apps in the past that worked on iPhone ,Mac and Windows.
Tom