Jump to content

Recommended Posts

Posted

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.

Posted

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?

Posted

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!

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...