Jump to content
Sign in to follow this  
DJG

Fileopen works with a variable but Fileclose doesn't?

Recommended Posts

DJG

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.

Share this post


Link to post
Share on other sites
DJG

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?

Share this post


Link to post
Share on other sites
DJG

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!

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×