creating a log file error


#1

I have a script that imports files and writes to a log file. If the log file does not exist it gets created

			
local exportfilelog = txt_dir.text + "\\importlog.txt"
local importFileList = txt_dir.text + "\\importFileList.txt"
if doesFileExist exportfilelog == false then cf = createFile exportfilelog

It creates the file OK but when I try to write to it, it errors telling me the file doesn’t exist. It works on the second pass because the file already exists. What do I have to do to make max see the newly created file on the first go-round?

			
fn writetolog dir larr fileLog=
(				
local t = localtime							
local exportlog = openfile fileLog mode:"a"
format "%
" t to:exportlog
for i = 1 to larr.count do format "% % seconds
" larr[i][1] larr[i][2] to:exportlog
format "<--##############################-->
" to:exportlog	
close exportlog
)

Thanks!


#2

are you closing cf after you create it?


#3

like this? Still errors


			if doesFileExist exportfilelog == false then
				( 
					cf = createFile exportfilelog
					close exportfilelog
				)

-- >> MAXScript Rollout Handler Exception:
-- Runtime error: FileStream cannot create: C:\Plant 3D Models\OriginalModels\importlog.txt <<


#4
close cf

DOH! Thanks lo!


#5

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.