New topic: Truncate a file?
<http://forums.realsoftware.com/viewtopic.php?t=31427> Page 1 of 1 [ 3 posts ] Previous topic | Next topic Author Message JustSomeGuy Post subject: Truncate a file?Posted: Sat Dec 05, 2009 6:50 pm Joined: Fri May 11, 2007 11:35 am Posts: 673 I have a file whose size needs to get smaller. I remember a long time ago, that to truncate a file you did an fseek to a position then wrote 0 bytes at that location. This was a 'signal' to the operating system that you wanted to truncate the files size. Ok.. Well in RB how can I truncate a file? (Without having to copy only as much data as I need to a new file, delete the old file and rename the new file to the old files name.) (Which seems problematic and slow to me.) _________________ 6502 Assembler on Steroids Top timhare Post subject: Re: Truncate a file?Posted: Sat Dec 05, 2009 7:39 pm Joined: Fri Jan 06, 2006 3:21 pm Posts: 6892 Location: Portland, OR USA Open a binary stream and set its length to whatever you desire. Top JustSomeGuy Post subject: Re: Truncate a file?Posted: Sat Dec 05, 2009 7:50 pm Joined: Fri May 11, 2007 11:35 am Posts: 673 So if the file exists... Code:Dim stream as new BinaryStream.Open(f, true) Stream.length = newsize Stream.Close grrrrreeat... _________________ 6502 Assembler on Steroids 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]
