New topic: Open an existing file?
<http://forums.realsoftware.com/viewtopic.php?t=31406> Page 1 of 1 [ 3 posts ] Previous topic | Next topic Author Message JustSomeGuy Post subject: Open an existing file?Posted: Thu Dec 03, 2009 3:06 pm Joined: Fri May 11, 2007 11:35 am Posts: 668 Code:f2 = New FolderItem(f.child("Images").Child("AnalyzeFiles").Child("my.img")) if f2 <> Nil then stream = BinaryStream.Create(f2, true) end if This code works fine to create my file... However if I later want to open and write to the now existantant file... what do I do? This looks right doesn't it? Code:f2 = New FolderItem(f.child("Images").Child("AnalyzeFiles").Child("my.img")) if f2 <> Nil then stream = BinaryStream.Open(f2, true) end if _________________ A picture paints a thousand words. A thought paints a thousand pictures. Top kendoll Post subject: Re: Open an existing file?Posted: Thu Dec 03, 2009 6:29 pm Joined: Mon Jul 17, 2006 10:39 am Posts: 1542 JustSomeGuy wrote:However if I later want to open and write to the now existantant file... what do I do? This looks right doesn't it? Code:f2 = New FolderItem(f.child("Images").Child("AnalyzeFiles").Child("my.img")) if f2 <> Nil then stream = BinaryStream.Open(f2, true) end if "f2" should never be nil. You'd get a NilObjectException for one of the previous directories first. That said, the correct way to see if a file exists or not is to check FolderItem.Exists. Try something like: Code:f2 = New FolderItem(f.child("Images").Child("AnalyzeFiles").Child("my.img")) if f2 <> Nil then If f2.Exists Then stream = BinaryStream.Open(f2, true) Else stream = BinaryStream.Create(f2, true) End If end if _________________ Kenneth McCleary [email protected] Top timhare Post subject: Re: Open an existing file?Posted: Thu Dec 03, 2009 6:33 pm Joined: Fri Jan 06, 2006 3:21 pm Posts: 6882 Location: Portland, OR USA The use of "new folderitem" in your code is entirely unnecessary and only clutters it up. Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 3 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]
