I'm trying to build a program that gets users name at first. This user names are kept in a text file. After user logins, according to the user's name, I want user to be lead his/her specific informations. I figured out that I can only do it with a file that is created when he sign up for an account which I direct him with my sign up button in Livecode. While he/she create his account I want to create a specific file for his/her. Can you help me with it please? PS: I don't want to do it with a database right now. I just want to learn how to create a file without a specific name like put specialFolderPath("documents")&"/userLoginCridentials.txt" into tFile put URL("file:"&tFile) into myFile Instead of this "userCridentials.txt" I want something user can create with his own name :)
1 Answers
Having a little problem to understand your question. Are you targeting mobile or desktop? Are you having problem saving or reading the data?
If saving is you problem
On desktop you can use:
ask file "Save file as:"
then you get the filename back in it so you can use:
if it is not empty then
# We have a complete file path in 'it'
put it into tFile
put tData into url ("file:" & tFile)
end if
If you targeting mobile and would like to save into the specialFolderPath("Documents")
you can get the filename from a field and then save to that file. E.g. if you have a field named 'fileName' you can use something like:
put tData into url("file:" & specialFolderPath("Documents") & "/" & field "fileName"
Of course you should do some error checking to ensure that a user don't overwrite existing files without at least asking for permission, etc.
You can of course use a variable instead of a field...
If reading data is your problem
On desktop you can use:
answer file "Open File:"
Same as above but you now read data instead:
if it is not empty then
# We have a complete file path in 'it'
put it into tFile
put url ("file:" & tFile) into tData
end if
on mobile you probably would like to present a list with the user-created files. In LiveCode you can list all files in the defaultFolder with the files
. But you must set the defaultFolder to the folder you want to list.
set the defaultFolder to specialFolderPath("Documents")
put the files into tFiles
Now tFiles
contains every file in that folder and you can filter it, display it in a list etc. E.g:
filter tFiles with "*.txt"
put tFiles into
If your problem is how to remember the "current" file name
Whenever you restart your app every variable is reset. So everything you want to remember between runs needs to be saved before your app quits. And for that you need a predefined filename. SO then your procedure will be:
- Read in the predefined file.
- Grab the file name from within that file
- Read the file
If your problem is something else
Sorry, then I misunderstood your question...

- 426
- 3
- 9
-
I'm targeting mobile. And my question is simply that can I let user write the name of the document file I wanna save his information into or do I have to specify the file name? – Ali Kemal Tanrıverdi Sep 16 '15 at 08:05
-
In that case, the answer is there under 'If saving is your problem': put tData into url("file:" & specialFolderPath("Documents") & "/" & field "fileName". If you would rather have them enter it in a message box rather than entering it into a field on the card, you could use something like: ask "enter your name", put it into tName, put tSomeData into url("file:" & specialFolderPath("documents") & "/" & tName & ".txt") – David Williams Sep 16 '15 at 10:28