Page 1 of 1

Trying to create a text file

Posted: Sat Aug 28, 2010 9:28 pm
by matt
Hi Everyone,

I'm trying to learn how to create a file from within RunRev and store it to a location selected by the user. This is the code I've written so far.

Code: Select all

on mouseUp
   answer folder "What is the folder name?" titled "Folder Name" 
   put it into tFolder
   ask "Enter a file name" titled "File name"
   put it into tFileName
   
   put "/" before tFileName
   put tFolder&&tFileName into tOpenThis
   
   open file tOpenThis for write
   write "Testing, testing" to file tOpenFile
   close file tOpenFile
end mouseUp
It compiles without any errors, and it seems to run. The issue is that no file is actually created in the folder I've selected on my desktop.

I'm hoping that you can suggest what I might be missing. Thanks! -Matt

Re: Trying to create a text file

Posted: Sat Aug 28, 2010 9:50 pm
by bn
Hi Matt,
the problem is that by issuing "&&" in
put tFolder&&tFileName into tOpenThis
you insert a space and that folder does not exist.
if you just say

Code: Select all

put tFolder & tFileName into tOpenThis
it works
You might also have a look at ask file

Code: Select all

ask file "choose a name and location" with "myExample.txt"
and also the URL format for saving a file locally.

Code: Select all

on mouseUp
   ask file "choose a name and location" with "myExample.txt"
   if it is not empty then put it into tPathAndFile
   put "someText" into URL ("file:" & tPathAndFile)
end mouseUp
if you want to use the URL format dont forget the brackets as in the example : URL ("file:" & tPathAndFile)
regards
Bernd

Re: Trying to create a text file

Posted: Sun Aug 29, 2010 12:43 am
by matt
Hi Bernd,

I looked at the answer box and thought it all looked Ok, but clearly I didn't see the extra space. I also much prefer this:
ask file "Choose a file name and location?" with "myexample.txt" titled "Folder Name"
to what I originally had. Thank you for your help!

-Matt