hi all,
this is my first time on this forum, seems like a good place to ask for a solution to im sure a small problem. All i want to do is create a file, log down some details then when the file reaches a certain size delete and start again. Heres what i have so far.
now everything works, apart from this bit
this deletes the file everytime, however i only want the file to be deleted when it reaches 10kb. can anyone help me with this, i am very much new to vbscript.
this is my first time on this forum, seems like a good place to ask for a solution to im sure a small problem. All i want to do is create a file, log down some details then when the file reaches a certain size delete and start again. Heres what i have so far.
Code:
Dim objNet, file
On Error Resume Next
Const ForAppending = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNet = CreateObject("WScript.Network")
If err.Number <> 0 Then 'If error occured then display notice
Wscript.Echo "Error create Network object" & err.number, err.description
err.Clear
End if
If objFSO.FileExists("C:\login.txt") Then
set file = filesys.GetFile("C:\login.txt")
if file.Size >= 10240 Then
WScript.echo "file size =" & file.Size
objFSO.DeleteFile("C:\login.txt")
End If
End If
If objFSO.FileExists("C:\login.txt") Then
Set objFile = objFSO.OpenTextFile("C:\login.txt", ForAppending)
objFile.Write Now
objFile.Write(" ")
objFile.Write(objNet.Username)
objFile.WriteLine
objFile.Close
Set objNet = Nothing
Else
Set objFile = objFSO.CreateTextFile("C:\login.txt")
Set objFile = objFSO.OpenTextFile("C:\login.txt", ForAppending)
objFile.Write Now
objFile.Write(" ")
objFile.Write(objNet.Username)
objFile.WriteLine
objFile.Close
Set objNet = Nothing
End If
now everything works, apart from this bit
Code:
If objFSO.FileExists("C:\login.txt") Then
set file = filesys.GetFile("C:\login.txt")
if file.Size >= 10240 Then
WScript.echo "file size =" & file.Size
objFSO.DeleteFile("C:\login.txt")
End If
End If
this deletes the file everytime, however i only want the file to be deleted when it reaches 10kb. can anyone help me with this, i am very much new to vbscript.