Forums > Javascript

File bugs! File.writeline('') fails; can't truncate existing file; docs bug.

January 15, 2010 | 6:18 pm

Hello! If you recall I found a bug with the File class two months ago (see this thread: http://cycling74.com/forums/topic.php?id=21771)

I’ve found a couple of other bugs that I wanted to document here.

1. File.writeline('') does nothing.

File.writestring() writes a string to a file; File.writeline() also writes a string to a file, then adds a line separator (depending on the operating system).

File.writestring(") should do nothing BUT File.writeline(") should add a new line separator. Instead it does nothing.

WORKAROUND:

For my purposes, File.writeline(‘ ‘); works fine but leaves me with a lot of extra spaces at the end of lines. You could also look up the separator for your system and File.writestring(separator) directly.

2. File.open(filename, 'write') doesn’t truncate existing files.

If you open a file that already exists and write to it, but your new file is shorter than the existing file, you’ll see the new data at the beginning – and then the rest of the old data after that!

WORKAROUND:

Delete the old file by hand before overwriting it. Yes, annoying.

There seems to be no way to delete a file programmatically, or to truncate it when you close it.

3. The webpage documenting the File class has the wrong title!

See: http://www.cycling74.com/docs/max5/vignettes/js/jsfileobject.html

Its title is: Basic Javascript programming for the js and jsui objects
It should be: The File object.

(It makes it hard to find the right page when Googling).


January 15, 2010 | 9:54 pm

I should add that I’m running on Mac OS 10.6.2, "Snow Leper", on a dual Quad Xeon desktop.


January 15, 2010 | 10:57 pm

Thanks for the report. #1 and #3 should be fixed in the next release.

#2 is not a bug, since you might want to open a file and overwrite a specific part of the file without changing the file size. You just set the end of the file with File.eof = File.position;


January 15, 2010 | 11:28 pm

Yahoo!

Great, File.position, I should have figured that out. Thanks for the fast response…


Viewing 4 posts - 1 through 4 (of 4 total)