Sign in to follow this  
Followers 0
Datenshi

Issue with reading/writing filename from/to file

4 posts in this topic

#1 ·  Posted (edited)

Hello fellow Autoit coders, Im fairly new to Autoit scripting, ive learned using the online documentation and dissembling bots people have written. But i clearly lack overall knowledge about the language and so ive ran into a problem, I think ive tried almost everything for the passed 5 hours and nothing seem to work. This script is suppose to make a post on my phpBB forum with a filename which is kept inside a textfile. It's also suppose to check if the filename has already been posted by checking for the Filename inside another textfile which stores already posted Filenames, And if it does exist in this textfile it should skip to the next line of FileList.txt.

Problem = It doesnt read the UsedSubj.txt file it seems, it keeps posting the same filenames even if they're listed in UsedSubj.txt. Also there's a minor issue when the FileList.txt is out of Filenames to post it always post 1 empty line before sending me the msgbox that its done.

UsedSubj.txt : Script is suppose to check this textfile for a filename and if it exist in this file it wont post it, Its for eliminating the chance of the same link being posted twise.

FileList.txt : File contain filenames generated by another script and both my text files look like this inside...

Filename

Filename

Filename

---------------------------------------------------------------------------

$linenr = 1

$okeytogo = 0

$Usubfile = @ScriptDir & "\UsedSubj.txt"

$Filelist = @ScriptDir & "\FileList.txt"

While 1

Sleep(5000)

MouseClick("left",525, 267)

$FileName = FileReadLine($Filelist,$linenr)

If @error = -1 then

MsgBox(1, "Result:", "DONE")

Endif

$UsedCheck = StringInStr($FileName,$Usubfile)

If not $UsedCheck = 0 then

MsgBox(1,"","Already Exist!",2 )

Else

FileWriteLine($Usubfile,$FileName)

Sleep(100)

ControlSend( "mysite.com","","",$FileName)

$linenr += 1

$okeytogo = 1

EndIf

Sleep(500)

MouseClick("left",558, 385)

;Start of Post Link

If $okeytogo = 1 then

ControlSend( "mysite.com","","","[bBcode]Senaste/" & $FnameLinker & ".avi[/bBcode]")

Sleep(100)

;MouseClick("left",674, 800) SUBMIT DISABLED FOR TESTING

$okeytogo = 0

Sleep(7000)

ControlSend( "mysite.com","","","^l")

Sleep(500)

ControlSend( "mysite.com","","","http://www.mysite.com/posting.php?mode=newtopic&f=11{ENTER}")

Endif

WEnd

-----------------------------------

Edited by Datenshi

Share this post


Link to post
Share on other sites



Hello fellow Autoit coders, Im fairly new to Autoit scripting, ive learned using the online documentation and dissembling bots people have written. But i clearly lack overall knowledge about the language and so ive ran into a problem, I think ive tried almost everything for the passed 5 hours and nothing seem to work. This script is suppose to make a post on my phpBB forum with a filename which is kept inside a textfile. It's also suppose to check if the filename has already been posted by checking for the Filename inside another textfile which stores already posted Filenames, And if it does exist in this textfile it should skip to the next line of FileList.txt.

Problem = It doesnt read the UsedSubj.txt file it seems, it keeps posting the same filenames even if they're listed in UsedSubj.txt. Also there's a minor issue when the FileList.txt is out of Filenames to post it always post 1 empty line before sending me the msgbox that its done.

UsedSubj.txt : Script is suppose to check this textfile for a filename and if it exist in this file it wont post it, Its for eliminating the chance of the same link being posted twise.

FileList.txt : File contain filenames generated by another script and both my text files look like this inside...

Filename

Filename

Filename

---------------------------------------------------------------------------

$linenr = 1

$okeytogo = 0

$Usubfile = @ScriptDir & "\UsedSubj.txt"

$Filelist = @ScriptDir & "\FileList.txt"

While 1

Sleep(5000)

MouseClick("left",525, 267)

$FileName = FileReadLine($Filelist,$linenr)

If @error = -1 then

MsgBox(1, "Result:", "DONE")

Endif

$UsedCheck = StringInStr($FileName,$Usubfile)

If not $UsedCheck = 0 then

MsgBox(1,"","Already Exist!",2 )

Else

FileWriteLine($Usubfile,$FileName)

Sleep(100)

ControlSend( "mysite.com","","",$FileName)

$linenr += 1

$okeytogo = 1

EndIf

Sleep(500)

MouseClick("left",558, 385)

;Start of Post Link

If $okeytogo = 1 then

ControlSend( "mysite.com","","","[bBcode]Senaste/" & $FnameLinker & ".avi[/bBcode]")

Sleep(100)

;MouseClick("left",674, 800) SUBMIT DISABLED FOR TESTING

$okeytogo = 0

Sleep(7000)

ControlSend( "mysite.com","","","^l")

Sleep(500)

ControlSend( "mysite.com","","","http://www.mysite.com/posting.php?mode=newtopic&f=11{ENTER}")

Endif

WEnd

-----------------------------------

You want to see is a string $Usubfile already exists in a file and if not then add it I think. So the first thing is that you have a FileReadLine which just reads one line, but the string might be in another line. So you need to say

$FileName = FileRead($Filelist);

then $FileName has every line, and you can say

If not StringinStr($FileName,$Usubfile) then addthestring

But if you need to add the string to the file use

$hF = FileOpen ( $Filelist , 1 );1 to append otherwise it will replace everything with the line you write
FilewriteLine($hF,$Usubfile);add $UsubFile to the list
FileClose($hF);close the file

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hm i modified the code a bit, but im not sure you understod my problem, Its like this:

$Usubfile = @ScriptDir & "\UsedSubj.txt"
$Filelist = @ScriptDir & "\FileList.txt"

       While 1
    Sleep(5000)
    MouseClick("left",525, 267)
    $FileSelect = FileReadLine($Filelist,$linenr)       ; Selects 1 Filename from filelist.txt to be used ( works )
    If @error = -1 then
        MsgBox(1, "Result:", "DONE")
        Endif
    $loadused = FileRead($Usubfile)             ; Loads all the previous used filenames from Usedsubj.txt ( not sure )
    $UsedCheck = StringInStr($FileSelect,$loadused)     ; This code is suppose to make it check for the 
             If not $UsedCheck = 0 then          ; selected filename in the already used filename file UsedSubj.txt     ; 
        MsgBox(1,"","Already Exist!",2 )        ; if the line exist in UsedSubj.txt the MsgBox shows up. (Does'nt work)
    Else
    FileWriteLine($Usubfile,$FileSelect)            ; If the filename didnt already exist in the UsedSubj.txt file it writes it to it ( works )
    Sleep(100)
    ControlSend( "mysite.com","","",$FileSelect)    ; Writes the Filename selected onto my PHPBB forum post. ( works )
    $linenr += 1
    $okeytogo = 1
    EndIf

So the problem is, the line which is suppose to check if the Selected Filename exist inside UsedSubj.txt does not work, resulting in the same filename's being posted more then once.

Edited by Datenshi

Share this post


Link to post
Share on other sites

Logic error. Too many double/triple negatives.

Change the two lines where you do the check to one of the following. Either:

$UsedCheck = StringInStr($FileSelect, $loadused)        ; This code is suppose to make it check for the
    If $UsedCheck <> 0 Then             ; selected filename in the already used filename file UsedSubj.txtoÝ÷ ÚãºËZºÚ"µÍRYÝ[Ò[Ý    ÌÍÑ[TÙ[XÝ  ÌÍÛØYÙY
H[

:-)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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  
Followers 0