PDA

View Full Version : fopen and strings that have a linebreak in them


tymznd
01-10-2004, 03:59 AM
I have been using BBedit for quite sometime to write my mel scripts. I recently have been using scripts to read files and the data they contain.

I seem to be having an issue with linebreaks... (I tried using a different editor and got similiar results). The code goes like this (simplified of course)
$nextLine = `fgetline $fileID`;
while ($nextLine != "\n"){
$fileName = $nextLine;
fopen $fileName;
}
This works fine if the initial file only contains a single line but if the file contains a list of file names I get an error (again simplifed for readability)
/Users/.../.../maya/projects/.../.../v2/L_foot2/targetFile.mel
// Warning: ; was NOT found
//
The file is there but I believe that I have isolated it to the fact that since the file has linebreaks that separate the file list.... it somehow breaks at the fopen

brubin
01-11-2004, 11:57 PM
if life were that simple we wouldn't need computers, right? :)

first: are you on NT? (or which?)
in some cases only fractions of a path will be used because of " "-whitespaceChars. in a path. NT causes problems because of the use of "\" as the seperator. you will have to unquote " " and "\" in pathnames.

what's in the file you're reading from? (example?)

what does replacing "fopen $fileName;" with "print (">"+$fileName+"<\n") ;" tell you?
it should give you something like:
">/user/path/file.mel<"

instead of:
">/user/path/file.mel
<"
or even something else instead.

your "while" -statement only takes care of a line exactly like "\n" and nothing but, so it doesn't take care of any occurence of "\r", or lines ending with either \n or\r. i personally would try a "match"- or "gmatch"-statement, or tokenize for \n or \r. i would make sure that the string returned is a valid file ->"filetest" etc., befor i'd use it in a "fopen"-procedure.

if using "fopen" use another int $id = `fopen $fileName` (but you probably know that.)

HIH
s.

CGTalk Moderation
01-17-2006, 04:00 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.