Hello everyone I am new in autoit What I want to do is , writing my application events and erros and save them in a '.txt' file then change filename each time when the file size become bigger than (1 MB ) ( I do not want a lot of lines in the same file) for example , my app is writing into "My_app_events0.txt" then when it's size become 1MB or more it start writing into "My_app_events1.txt" without deleting the first file , and then "My_app_events2.txt" ,"My_app_events3.txt" then "My_app_events4.txt" ...ect I am using this function to get file size Func GetFileSize($inputSize, $inputUnit = 1, $outputPlaces = 2, $outputString = True, $inputBits = False, $outputBits = False, $outputUnit = -4)
Local $unitNames[9] = ["","K","M","G","T","P","E","Z","Y"]
Local $bytes = $inputSize * 1024 ^ $inputUnit
Local $b = "B"
If $inputBits Then $bytes /= 8
If $outputBits Then
$bytes *= 8
$b = "b"
EndIf
If $outputUnit < 0 Then
Local $outputMax = Abs($outputUnit)
$outputUnit = Int(Log($bytes)/Log(1024))
If $outputUnit > $outputMax Then $outputUnit = $outputMax
EndIf
If $outputString Then
Return String(Round($bytes / 1024 ^ $outputUnit, $outputPlaces)) & $unitNames[$outputUnit] & $b
Else
Return Round($bytes / 1024 ^ $outputUnit, $outputPlaces)
EndIf
EndFuncI've Tried to write this methode but it doesn't work I do't know why it consist in getting the file number from a registry key and add ( +1 ) each time we change the file to write into . $Key = "HKEY_CURRENT_USER\Software\My_app_events"
$Val = 'Number'
$Read_Number = RegRead($Key,$Val)
;$LogC = FileOpen($LogN,2)
If RegRead($Key,$Val) <> "" Then ; a number already exists So this is not my first run
$Fname = "My_app_events" & $Read_Number & ".txt" ; Read our filename
Else ; So this is my 1st Run
RegWrite($Key,$Val,"REG_SZ","0") ; Write First number = 0
$Fname = "My_app_events" & $Read_Number & ".txt" ; Read our filename
EndIf
while 1
$KeySize = GetFileSize($LogF)
If $KeySize >= 1024 Then ; If file Size > 1 MB (1000 KB )
$OlD_Num = RegRead($Key,$Val) ; Getting old Number
RegWrite($Key,$Val,"REG_SZ","") ; Empty the number
RegWrite($Key,$Val,"REG_SZ",$OlD_Num +1) ; Writing the next Number
Restart()
EndIf
WriteEvents()
Sleep(1000)
Wend
Func WriteEvents($What_to_write)
FileWrite($Fname,$What_to_write)
endfunc
Func Restart()
Run(@Autoitexe) ; Restart
Exit
EndfuncI tried also the same way but with another methode which read file name from another '.txt' file but it didn't work to I removed it after . I wish I will get help , thanks in advance and Sorry for my bad English