Sign in to follow this  
Followers 0
seesoe

file read and move

9 posts in this topic

hello,

i have 2 files submitted.txt and done.txt

for helps sake, in the submitted file i have a php script that writes a line to it every time it is executed, the line structure is like this:

[x,x,x]

im trying to read the last line in the submitted file ([x,x,x]) and put the first x in a var ($id) and then when im done messing with it i want MOVE the line ([x,x,x]) to the done file

i can't seem to figure it out, it sounds easy to me but when i try to do it i get lost.

if anyone can help please that would be greatly appreciated:), thanks

cheers

seesoe

Share this post


Link to post
Share on other sites



What about _FileReadToArray() and StringRegExp?

Share this post


Link to post
Share on other sites

well technically the submitted file will only have one [] line in it, because the script will move it to done.txt when it sees a line in there,

i was able to read that line with _FileReadToArray(), but i don't really understand StringRegExp...

Share this post


Link to post
Share on other sites

Well, you can show more than just generic structure like [x,x,x] because this way it's sufficient to StringSplit it with a comma and StringTrimLeft and StringTrimRight by 1 character on the second and the last array element returned by StringSplit (the first element holds the array size).

Share this post


Link to post
Share on other sites

ok so i have the following done

$submit = "submitted.txt"
$done = "done.txt"

While 1
  $order_size = FileGetSize($submit)
  
    If $order_size > 0 Then
        Dim $aRecords
        If Not _FileReadToArray($submit,$aRecords) Then
            MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
            Exit
        EndIf
  
                $file_line_1     =    StringTrimLeft($aRecords[1], 1)
        $file_line_2     =    StringTrimRight($file_line_1, 1)
        $file_line_3    =    StringSplit($file_line_2, "~")

        $id_1            =    StringTrimLeft($file_line_3[1], 4)
        $id                =    StringTrimRight($id_1, 1)

        $url            =    _HTTPEncodeString($var&"="&$id)
        $socket            =    _HTTPConnect($host)
        $get            =    _HTTPPost($host,$page,$socket,$url)
        $recv            =    _HTTPRead($socket,1)
  
        MsgBox(0, '', $recv[4]&"   "&$order_size)
  
        FileWriteLine($done, $aRecords[1])
        FileWrite($submit, "")
        Exit
    EndIf
  WEnd

im now stuck on 2 things..

1. im trying to figure out a better way to keep tabs on the $submit file when it gets written to, normally the file is 0kb until an order is placed, when that happens it goes to about 200kb, then this script runs and will move that line to another file, thusly setting $submit back to 0kb, you get my drift, im trying to make it where it will work that way though.

2. the 4th from the bottom line, above that line i write the first collected line from submitted.txt to done.txt, then i want to clear the submitted.txt file, but im not sure how to do that.

again thank you:)

cheers

seesoe

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

autoit never ceases to amaze me in how easily things come together regardless of a noob or not:)

#include <String.au3>
#include <GuiListView.au3>
#include <HTTP.au3>
#include <GUIConstants.au3>
#include <file.au3>

$submit = "submitted.txt"
$done = "done.txt"

$host = "www.site.com"
$page = "/printed.php"
$var = "order_id"
;$id = "1"

While 1
$order_size = FileGetSize($submit)

    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then 
        Exit
    EndIf
    
    If $order_size > 0 Then
        FileOpen($submit, 0)
        Dim $aRecords
        If Not _FileReadToArray($submit,$aRecords) Then
            MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
            Exit
        EndIf

        $file_line_1    =   StringTrimLeft($aRecords[1], 1)
        $file_line_2    =   StringTrimRight($file_line_1, 1)
        $file_line_3    =   StringSplit($file_line_2, "~")

        $id_1           =   StringTrimLeft($file_line_3[1], 4)
        $id             =   StringTrimRight($id_1, 1)
        $url            =   _HTTPEncodeString($var&"="&$id)
        $socket         =   _HTTPConnect($host)
        $post           =   _HTTPPost($host,$page,$socket,$url)
        $recv           =   _HTTPRead($socket,1)
        
        FileClose($submit)
        
        MsgBox(0, '', $recv[4])

        FileOpen($done, 1)
            FileWriteLine($done, $aRecords[1])
        FileClose($done)

        FileOpen($submit, 2)
            FileWrite($submit, "")
        FileClose($submit)

        Exit
    EndIf
WEnd

thanks again Authenticity,

cheers

seesoe

Edited by seesoe

Share this post


Link to post
Share on other sites

i forgot all about the second part of my question about monitoring the submitted.txt file for changes?...

how can i accomplish that?

Share this post


Link to post
Share on other sites

Well that could be difficult because I don't think you can have 2 streams to the same file open. Perhaps you could check the last modified time?

Share this post


Link to post
Share on other sites

with much failed trials to get something going i finally got something working:)

#652017

thanks!

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