Simply Maya User Community

Simply Maya User Community (https://simplymaya.com/forum/index.php)
-   Programming (https://simplymaya.com/forum/forumdisplay.php?f=32)
-   -   writing a text file (https://simplymaya.com/forum/showthread.php?t=14707)

Dann 14-12-2004 12:04 AM

writing a text file
 
OK, since you all have been so helpful in my endeavours to get my MEL chops up to par, I'm back again with another question.

I'm trying to write out a text file that lists most of the render globals. I've basically got everything working except for one major problem. I've tried using both fwrite and fprint, but they both only seem to append the specified file.What I need to do is either overwrite the file, or erase the file before re-writing it. Anyone have any thoughts on how to do that?

Thanks again,
-dann

Dann 14-12-2004 02:52 AM

got it, used a combo or fprint and fgetline.

Alan 14-12-2004 09:16 AM

int $fileid = `fopen $filename "w"`;
fprint $fileid "my lines of code whatever I want to write \n";
fclose $fileid;

That's how you do it.

Alan

Dann 14-12-2004 09:19 AM

yup, that's part of it, but that appends the file so i had to do a lot more to replace lines within the file. Thanks though.

Alan 14-12-2004 11:14 AM

no it doesn't:

open to write (will overwrite the file)
int $fileid = `fopen $filename "w"`;

open to append to the file
int $fileid = `fopen $filename "a"`;

//from the docs
"w" open file for writing (destroys prior contents of file).
"a" append for writing (appends to end of file).
"r" open for reading.

;)

Alan

Dann 14-12-2004 10:25 PM

You are absolutly correct! I could have sworn I tried the "w" and had it append my file. I still had to read some elements of the file into varibles before clearing it, but "w" is cleaner than using a system command to delete the file first.

Regardless, thanks for the help.


All times are GMT. The time now is 01:10 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Simply Maya 2018