Jump to content
Sign in to follow this  
PantZ4

Log problem

Recommended Posts

PantZ4

So I have made my own write to log function, which works. But for some strange reason my read log function is not working.

The function it self:

Func _ReadLog($FilePath,$OutputFilePath,$Password,$EncryptLevel = 1,$StringSpilt = ".")
    Local $File = FileOpen($FilePath,1), $Text = "", $Array
    $Text = FileRead($File)
    FileClose($File)
    $File = FileOpen($OutputFilePath,1)
    $Array = StringSplit($Text,$StringSpilt,1)
    For $x = 1 To $Array[0] Step 1
        FileWrite($File,$Array[$x])
    Next
    FileClose($File)
EndFuncoÝ÷ Ø̬r¸©¶+-¢âÚ)¢Ëaz·¬ Z½éuæÅ©©êÖ®¶­sb4æ6ÇVFRfÇCµ7G&æræS2fwC° ¥õw&FTÆör×Fö7VÖVçG4F"fײgV÷C²b3#³çGBgV÷C²ÂgV÷C´ÆörFW7BgV÷C²ÂgV÷C³gV÷C²¥õ&VDÆör×Fö7VÖVçG4F"fײgV÷C²b3#³çGBgV÷C²Ä×Fö7VÖVçG4F"fײgV÷C²b3#³"çGBgV÷C²ÂgV÷C³gV÷C² ¤gVæ2õw&FTÆörb33c´fÆUFÂb33cµFWBÂb33cµ77v÷&BÂb33c´Væ7'DÆWfVÂÒÂb33cµ7G&æu7ÇBÒgV÷C²âgV÷C² Æö6Âb33c´fÆRÒfÆT÷Vâb33c´fÆUFà fÆUw&FRb33c´fÆRÅõ7G&ætVæ7'BÂb33cµFWBÂb33cµ77v÷&BÂb33c´Væ7'DÆWfVÂfײb33cµ7G&æu7ÇB fÆT6Æ÷6Rb33c´fÆR¤VæDgVæ0 ¤gVæ2õ&VDÆörb33c´fÆUFÂb33c´÷WGWDfÆUFÂb33cµ77v÷&BÂb33c´Væ7'DÆWfVÂÒÂb33cµ7G&æu7ÇBÒgV÷C²âgV÷C² Æö6Âb33c´fÆRÒfÆT÷Vâb33c´fÆUFÃÂb33cµFWBÒgV÷C²gV÷C²Âb33c´'& b33cµFWBÒfÆU&VBb33c´fÆR fÆT6Æ÷6Rb33c´fÆR b33c´fÆRÒfÆT÷Vâb33c´÷WGWDfÆUFà b33c´'&Ò7G&æu7ÆBb33cµFWBÂb33cµ7G&æu7ÇBà f÷"b33c·ÒFòb33c´'&³Ò7FW fÆUw&FRb33c´fÆRÂb33c´'&²b33c·Ò æW@ fÆT6Æ÷6Rb33c´fÆR¤VæDgVæ0

For me it returns a empty txt file.

Any ideas why?

Share this post


Link to post
Share on other sites
evilertoaster

Something right quick I noticed is that you're using FileOpen($FilePath,1) which opens it in write mode. During the LogRead function maybe using FileOpen($FilePath,0) would be more appriopriate (although i think it's not required).

Share this post


Link to post
Share on other sites
DjDeep00

Make sure the file exists when you use "FileOpen($OutputFilePath,0)". If not then it will return the error -1. If it doesn't exist then you dont have to open the file.

Share this post


Link to post
Share on other sites
PantZ4

Something right quick I noticed is that you're using FileOpen($FilePath,1) which opens it in write mode. During the LogRead function maybe using FileOpen($FilePath,0) would be more appriopriate (although i think it's not required).

Oh yeah. Thanks :shocked:

Make sure the file exists when you use "FileOpen($OutputFilePath,0)". If not then it will return the error -1. If it doesn't exist then you dont have to open the file.

I use 1. So it should be created.

When opening a file in write mode, the file will be created if it does not exist.

Edited by Mr. Zero

Share this post


Link to post
Share on other sites
DjDeep00

Try this:

Func _ReadLog($FilePath,$OutputFilePath,$Password,$EncryptLevel = 1,$StringSpilt = ".")

Local $File = FileOpen($FilePath,0), $Text = "", $Array

$Text = FileRead($File)

FileClose($File)

$File = FileOpen($OutputFilePath,0)

$Array = StringSplit($Text,$StringSpilt,1)

For $x = 1 To $Array[0]

FileWrite($OutputFilePath,$Array[$x])

Next

FileClose($File)

EndFunc

Share this post


Link to post
Share on other sites
PantZ4

Try this:

Func _ReadLog($FilePath,$OutputFilePath,$Password,$EncryptLevel = 1,$StringSpilt = ".")

Local $File = FileOpen($FilePath,0), $Text = "", $Array

$Text = FileRead($File)

FileClose($File)

$File = FileOpen($OutputFilePath,0)

$Array = StringSplit($Text,$StringSpilt,1)

For $x = 1 To $Array[0]

FileWrite($OutputFilePath,$Array[$x])

Next

FileClose($File)

EndFunc

Doing so will not create another file.

Share this post


Link to post
Share on other sites
DjDeep00

Doing so will not create another file.

I just tried it and it write to the file "2.txt" after reading from "1.txt". Here is the entire script:

#Include <String.au3>
#Include <Array.au3>
#Include <File.au3>

FileDelete("1.txt")
FileDelete("2.txt")

_WriteLog("1.txt","Log Test","1")
_ReadLog("1.txt","2.txt","1")

Dim $File_Array
_FileReadToArray("2.txt",$File_Array)
_ArrayDisplay($File_Array,"")

Func _WriteLog($FilePath,$Text,$Password,$EncryptLevel = 1,$StringSpilt = ".")
    Local $File = FileOpen($FilePath,1)
    FileWrite($File,_StringEncrypt(1,$Text,$Password,$EncryptLevel)&$StringSpilt)
    FileClose($File)
EndFunc

Func _ReadLog($FilePath,$OutputFilePath,$Password,$EncryptLevel = 1,$StringSpilt = ".")
    Local $File = FileOpen($FilePath,0), $Text = "", $Array
    $Text = FileRead($File)
    FileClose($File)
    $File = FileOpen($OutputFilePath,0)
    $Array = StringSplit($Text,$StringSpilt,1)
    For $x = 1 To $Array[0]
        FileWrite($OutputFilePath,$Array[$x])
    Next
    FileClose($File)
EndFunc

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.