File Write Question
Posted: Sun Oct 04, 2015 4:51 pm
To make a long story short - I've got an idea for a large scale application that I would like to develop, and right now I'm creating little mini apps to learn the code behind the functionality of my big app idea.
I'm currently testing out file creation, and have a few questions -
Right now, I've got a text field that the user can input information, and save it to a file called "test.txt" on the users desktop.
My code is:
A) How can I check to see if there is a specific folder present in the specialFolderPath? - For example, I want to see if there is a folder called "ExampleFolder" on the desktop.
If that folder exists, save the text file in that folder. If the folder doesn't exist, create it, then save the file in that folder.
B) How can I use a variable from within my application as the file name used when saving the file?
Lets say I've got a variable "varName" that contains the string "John" - how can I use this information to save the file as "John.txt"?
C) Is it possible to create a custom file extension? This isn't something vital to my application idea, just something I am curious about.
So instead of creating a text file in a .txt format - maybe I want to save the text as a .xyz file or something like that - have it still be a text file, but appear to have a proprietary file format, if that makes sense.
I'm currently testing out file creation, and have a few questions -
Right now, I've got a text field that the user can input information, and save it to a file called "test.txt" on the users desktop.
My code is:
Code: Select all
command cmdSave
open file specialFolderPath("desktop") & "/test.txt" for write
put field "fldResult" into myText
write myText to file specialFolderPath("desktop") & "/test.txt"
close file specialFolderPath("desktop") & "/test.txt"
end cmdSave
If that folder exists, save the text file in that folder. If the folder doesn't exist, create it, then save the file in that folder.
B) How can I use a variable from within my application as the file name used when saving the file?
Lets say I've got a variable "varName" that contains the string "John" - how can I use this information to save the file as "John.txt"?
C) Is it possible to create a custom file extension? This isn't something vital to my application idea, just something I am curious about.
So instead of creating a text file in a .txt format - maybe I want to save the text as a .xyz file or something like that - have it still be a text file, but appear to have a proprietary file format, if that makes sense.