DJG Posted September 4, 2007 Posted September 4, 2007 I can't seem to get Fileclose (or FileMove) to work properly. Here's the relevant part of the script: $filename = InputBox("FileName", "What do you want to call the file?") $sDate = @YEAR & "-" & @MON & "-" & @MDAY & " - " & @HOUR & "h" & @MIN & "m" & @SEC & "s" $Tru = "C:\Tru - " & $sDate & $filename & ".txt" (later in the script) If $Trucount = 0 Then FileOpen($Tru, 1) FileWriteLine($Tru, $re & @CRLF) $Trucount = $Trucount + 1 If $Trucount >= $filesize Then FileClose($Tru) FileMove($Tru, "\\New\") $Trucount = 0 $sDate = @YEAR & "-" & @MON & "-" & @MDAY & " - " & @HOUR & "h" & @MIN & "m" & @SEC & "s" $Tru = "C:\Tru - " & $sDate & $filename & ".txt" EndIf As you can see, the current date and time is included as part of the filename. The script copies the value "$re" into a text file until it gets to a certain size, then opens a new file with the new current date and time. The files are created properly but FileClose and FileMove don't seem to work. It's as if I can open files with the variable "$Tru" but I can't close the file or move it to \\New\. Eventually, I get an error message stating the maximum number of open files has been exceeded. Can anyone shed some light on what I need to do in order to get FileClose and FileMove to work properly? Thanks in advance.
Developers Jos Posted September 4, 2007 Developers Posted September 4, 2007 FileOpen() returns a FIleHandle. This returned handle needs to be used with FIleClose() to close it (The File) - see Helpfile SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
DJG Posted September 4, 2007 Author Posted September 4, 2007 Hmm... I read it but I'm not 100% sure I understand. Perhaps if I rewrote the script like this it would work? Change: If $Trucount = 0 Then FileOpen($Tru, 1) To: If $Trucount = 0 Then $file = FileOpen($Tru, 1) And: FileClose($file) FileMove($file, "\\New\") Yes?
Developers Jos Posted September 4, 2007 Developers Posted September 4, 2007 more like: If $Trucount = 0 Then $file = FileOpen($Tru, 1) EndIf FileClose($file) FileMove($Tru, "\\New\") SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
DJG Posted September 6, 2007 Author Posted September 6, 2007 I think it's working now. Like a dummy I had to reread your response before realizing I needed to use a filehandle for FileClose and the filename variable for FileMove. No "max open files" error messages now and FileMove does seem to work. Thank you very much!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now