New topic: 

saving text files to a specific folder

<http://forums.realsoftware.com/viewtopic.php?t=47536>

         Page 1 of 1
   [ 5 posts ]                 Previous topic | Next topic          Author  
Message        SASS          Post subject: saving text files to a specific 
folderPosted: Sun Apr 07, 2013 9:24 pm                         
Joined: Mon Dec 28, 2009 10:36 pm
Posts: 9                I have heretofore used the open dialog to save files, 
but I want to do so without the dialog. I have successfully done so with 
images--the following code saves my pictures into the GamePhotos folder:
Dim f as FolderItem=getFolderItem("GamePhotos")
If f.Exists=false then
  f.CreateAsFolder
end
s="SomeName.jpg"
dim fChild as FolderItem
fChild=f.child(s)
OffScreenPicture.Save(fChild,Picture.SaveAsJPEG)

  
This works fine and I have saved twenty different images into that folder. But, 
when I try to do something similar with a text, I get the folder, but then it 
gets overwritten as a text file:

Dim f as FolderItem=getFolderItem("GamePoems")//Folder's name
s="Some Poem"
If f.Exists=false then
  f.CreateAsFolder
end
dim fChild as folderitem
fChild=f.child(s)
dim t as TextOutputStream
t=TextOutputStream.create(f)
t.write TextArea2.text
t.close


I do end up with my "Some Poem" file saved under the name "GamePoems," but I'm 
obviously missing something with that TextOutputStream.create(f), as it appears 
to be where the file gets overwritten. I'm not trying to do anything 
complicated--the files are saved in the same folder as the app.  I'm using Mac 
OSX 10.6.8 and at this point, I have no interest in trying to make it work on 
any other platform. But I don't know to get the "Some Poems" file into the 
"GamePoems" folder.

Thanks for your help!   
                             Top                timhare          Post subject: 
Re: saving text files to a specific folderPosted: Sun Apr 07, 2013 10:18 pm     
                    
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12214
Location: Portland, OR  USA                Quote:t=TextOutputStream.create(f)
You're using the wrong variable.  Use fchild instead of f.   
                             Top                SASS          Post subject: Re: 
saving text files to a specific folderPosted: Sun Apr 07, 2013 11:46 pm         
                
Joined: Mon Dec 28, 2009 10:36 pm
Posts: 9                timhare wrote:Quote:t=TextOutputStream.create(f)
You're using the wrong variable.  Use fchild instead of f.

Tried that and I get an IOException   
                             Top                timhare          Post subject: 
Re: saving text files to a specific folderPosted: Mon Apr 08, 2013 1:17 am      
                   
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12214
Location: Portland, OR  USA                Then you need to debug that.  The 
question is why are you getting an exception?  Does a file by the name 
"GamePoems" exist already, but it isn't a folder?  What happens if you manually 
create a folder by that name?   
                             Top                SASS          Post subject: Re: 
saving text files to a specific folderPosted: Mon Apr 08, 2013 2:25 am          
               
Joined: Mon Dec 28, 2009 10:36 pm
Posts: 9                timhare wrote:Then you need to debug that.  The 
question is why are you getting an exception?  Does a file by the name 
"GamePoems" exist already, but it isn't a folder?  What happens if you manually 
create a folder by that name?

Yes, that was it exactly. I didn't realize there was an earlier text file with 
that name. The save is working perfectly, now--putting the game texts into the 
folder. Thank you so much.   
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 5 posts ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to