Sign in to follow this  
Followers 0
profile

Doing me Head in

8 posts in this topic

HI

First thanks for looking, I have a script that i have created to split a txt file down and create a new one everytime the line #### is read, The issue i have is i cannot get the progress bar to give the % of the file written everytime it reads the #### line, I can get the progress bar to work reading out every line.

I have attached the script both files need to be in the same directory to run, I would be greatful if anyone can show me where i am going wrong, as i have spent weeks trying to get this running right.

I would like the progress bar to update everytime it reads the #### in the file.

thanks for looking.

Chris

Config_Generator.au3

Config.txt

Share this post


Link to post
Share on other sites



Hi,

i tried to solve your problem. The following example may not be the best solution :"> , but.... it does what you asked to do ;)

$x = 1
$j = 0
$lines = 0

While 1
    $ans = FileReadLine(@ScriptDir & '\Config.txt',$x)
    If @error = -1 Then ExitLoop; If end of file, then exitloop
    If StringLeft($ans,4) = '####' Then
    $lines +=1
    EndIf
    $x += 1
Wend
$x=0
While 1
    $ans = FileReadLine(@ScriptDir & '\Config.txt', $x)
    If @error = -1 Then ExitLoop; If end of file, then exitloop
    If StringLeft($ans,4) = '####' Then; Create new filename
        $j += 1
        $x += 1
        $filename = FileReadLine('config.txt', $x)
        $p = $j * 100 / $lines
        ProgressSet ($p, $filename & $fileext)  
        ContinueLoop
    EndIf
    $x +=1
    sleep(100)
WEnd

Share this post


Link to post
Share on other sites

Hi,

i tried to solve your problem. The following example may not be the best solution :"> , but.... it does what you asked to do ;)

$x = 1
$j = 0
$lines = 0

While 1
    $ans = FileReadLine(@ScriptDir & '\Config.txt',$x)
    If @error = -1 Then ExitLoop; If end of file, then exitloop
    If StringLeft($ans,4) = '####' Then
    $lines +=1
    EndIf
    $x += 1
Wend
$x=0
While 1
    $ans = FileReadLine(@ScriptDir & '\Config.txt', $x)
    If @error = -1 Then ExitLoop; If end of file, then exitloop
    If StringLeft($ans,4) = '####' Then; Create new filename
        $j += 1
        $x += 1
        $filename = FileReadLine('config.txt', $x)
        $p = $j * 100 / $lines
        ProgressSet ($p, $filename & $fileext)    
        ContinueLoop
    EndIf
    $x +=1
    sleep(100)
WEnd
Thanks for your help, i keep getting an error on the $lines +=1 line ??

Share this post


Link to post
Share on other sites

Thanks for your help, i keep getting an error on the $lines +=1 line ??

hmmm, i am using the current beta version of autoit (v3.1.1.80). You could replace that with

$lines =$lines +1 if you want to use the current stable version.

The operator I used (+=) was implemented in Version 3.1.1.7 (beta). ;)

Share this post


Link to post
Share on other sites

hmmm, i am using the current beta version of autoit (v3.1.1.80). You could replace that with

$lines =$lines +1 if you want to use the current stable version.

The operator I used (+=) was implemented in Version 3.1.1.7 (beta). ;)

HI Jonk

I have upgraded to the latest beta and the script works now, thanks, i just now need to make it write everything after the #### into the new file until it comes accross the #### when it will start a new file again with the filename being the next line down after the ####.

thanks again pal.

Share this post


Link to post
Share on other sites

Here's another idea. This code only loops through the file once. The +2 is added to $currLen because @CRLF is assumed as the line terminator. May not be completely accurate but seems to work well with your example.

ProgressOn("Progress Meter", "Every File That is Written", "0 percent","", "", 16)
$x = 1
$fileLen = FileGetSize ( @ScriptDir & '\Config.txt' )
$currLen = 0
DirCreate ( $outloc )

While 1
    $ans = FileReadLine(@ScriptDir & '\Config.txt', $x)
    If @error = -1 Then ExitLoop; If end of file, then exitloop
    $currLen = $currLen + StringLen($ans) + 2
    $prog = $currLen * 100 / $fileLen
    $x = $x + 1
    If StringLeft($ans,4) = '####' Then; Create new filename
        $filename = FileReadLine('config.txt', $x)
        ContinueLoop
    EndIf
    $save = $outloc & "\" & $filename & $fileext
    FileWriteLine($save, $ans); Write file
    ProgressSet ( $prog, $filename & $fileext)
    sleep(100) 
WEnd


ProgressSet(100 , "Done", "Complete")

BlueBearrOddly enough, this is what I do for fun.

Share this post


Link to post
Share on other sites

Here is the full script with my solution:

; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.0
; Language:    English
; Platform:    Win9x / NT
; Author:        C McCormack chrismccormack@vodat-int.com
;
; Script Function:
;   Template AutoIt script.
;
; ----------------------------------------------------------------------------


; ----------------------------------------------------------------------------
; Set up our defaults
; ----------------------------------------------------------------------------

;AutoItSetOption("MustDeclareVars", 1)
;AutoItSetOption("MouseCoordMode", 0)
;AutoItSetOption("PixelCoordMode", 0)
;AutoItSetOption("RunErrorsFatal", 0)
;AutoItSetOption("TrayIconDebug", 1)
;AutoItSetOption("WinTitleMatchMode", 4)


; ----------------------------------------------------------------------------
; Script Start
; ----------------------------------------------------------------------------


; Prompt the user to run the script - use a Yes/No prompt (4 - see help file)
$answer = MsgBox(4, "YOU ARE ABOUT TO THE CONFIG SPLIT PROGRAM", "PLEASE CLICK YES TO CONTIUNE")


; Check the user's answer to the prompt (see the help file for MsgBox return values)
;~; If "No" was clicked (7) then exit the script
If $answer = 7 Then
    MsgBox(0, "Closing Down", "Click OK to exit.")
    Exit
EndIf

SplashTextOn("Folder Browse", "Please Select the folder you require as the " & @CRLF & @CRLF & "Output location." , -1, 200, -1, -1, 0, "", 24)
Sleep(5000)
SplashOff()

$OUTLOC = inputbox("OUTPUT LOCATION", "Please enter the location to save the files."& @CRLF & @CRLF &"Example C:\test")
$OUTLOC = FileSelectFolder("Choose a file.", "")
$outloc2 = msgbox(4, "The location you have entered is", $OUTLOC)
If $outloc2 = 7 Then
    MsgBox(0, "Closing Down", "Click OK to exit.")
    Exit
EndIf

Global $filename
Global $p

$outloc = "D:\test\bananarama"
$fileext = inputbox("FILE EXTENSION REQUIRED", "Please enter the File EXTENSION you require."& @CRLF & @CRLF &"Extension of .TXT enter TXT"& @CRLF & @CRLF &"Extension of .NEW enter NEW")
$fileext2 = MsgBox(4, "The EXTENSION you have entered is ", $fileext)
If $fileext2 = 7 Then
    MsgBox(0, "Closing Down", "Click OK to exit.")
    Exit
EndIf

ProgressOn("Progress Meter", "Every File That is Written", "0 percent","", "", 16)
$x = 1
$j = 0
$lines = 0

While 1
    $ans = FileReadLine(@ScriptDir & '\Config.txt',$x)
    If @error = -1 Then ExitLoop; If end of file, then exitloop
    If StringLeft($ans,4) = '####' Then
    $lines +=1
    EndIf
    $x += 1
Wend
$x=1
MsgBox(0,"",$lines)
While 1
    $ans = FileReadLine(@ScriptDir & '\Config.txt', $x)
    If @error = -1 Then ExitLoop; If end of file, then exitloop
    If StringLeft($ans,4) = '####' Then; Create new filename
        $j += 1
        $x += 1
        $filename = FileReadLine('config.txt', $x)
        $p = $j * 100 / $lines
        ProgressSet ($p, $filename & $fileext)  
        ContinueLoop
    EndIf

    DirCreate ( $outloc )
    $save = $outloc & "\" & $filename & $fileext
    FileWriteLine($save, $ans); Write file
    $x +=1
    sleep(100)
WEnd

ProgressSet($ans , "Done", "Complete")
sleep(1500)
ProgressOff()

$complete = $outloc & ".  With The Extension Of ." & $fileext

msgbox(0, "Config Have now been created in the location", $complete)

@bluebearr

One loop looks better than my two. ;)

Share this post


Link to post
Share on other sites

HI

Thanks to all for your help, I can now see where i was going wrong.

Many thanks go out to you guys.

Chris

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