Sign in to follow this  
Followers 0
hispeed_mike

Help with Problem - Learning if this is where i need an array

6 posts in this topic

Hi,

Automating is not a real problem, but now I want to work alot more with variables and need a pointer in the right direction.

Below is a simple example of a progress bar I want to work out how to write.

Basically I need to work out how many files are in the folder then declare the $file1 variable as the size of file. As it goes through the loop and finds other files I want it to add this size to the next files size to get an amount I am going to transfer.

I would expect that this is then the value I would use to declare, to the progress bar that I want , to be 100% complete when it reaches this amount of data copied.

As you can already see I have not added the progress bar yet and have not put in the copy command. I would greatly appreciate a pointer to how to add the file sizes together and advice if I am going about this the right way.

Initially I want a file copy progress bar but would also like a script progress bar that shows me the progress of the entire script.

Thanks in Advance.

Mike

FileChangeDir (@DESKTOPDIR & "\From")

$search = FileFindFirstFile ("*.*")

While 1

$file = FileFindNextFile($search)

If @error Then ExitLoop

$file1 = FileGetSize ($file)

MsgBox(4096, "File:", $file & @CRLF & $file1)

WEnd

Share this post


Link to post
Share on other sites

Hi,

Automating is not a real problem, but now I want to work alot more with variables and need a pointer in the right direction.

Below is a simple example of a progress bar I want to work out how to write.

Basically I need to work out how many files are in the folder then declare the $file1 variable as the size of file. As it goes through the loop and finds other files I want it to add this size to the next files size to get an amount I am going to transfer.

I would expect that this is then the value I would use to declare, to the progress bar that I want , to be 100% complete when it reaches this amount of data copied.

As you can already see I have not added the progress bar yet and have not put in the copy command. I would greatly appreciate a pointer to how to add the file sizes together and advice if I am going about this the right way.

Initially I want a file copy progress bar but would also like a script progress bar that shows me the progress of the entire script.

Thanks in Advance.

Mike

FileChangeDir (@DESKTOPDIR & "\From")

$search = FileFindFirstFile ("*.*")

While 1

$file = FileFindNextFile($search)

If @error Then ExitLoop

$file1 = FileGetSize ($file)

MsgBox(4096, "File:", $file & @CRLF & $file1)

WEnd

You don't need arrays to do what you've asked for.

FileChangeDir (@DESKTOPDIR & "\From")
$search = FileFindFirstFile ("*.*")
$totalk = 0;space rquired
$totaln = 0;number of files to copy
While 1

    $file = FileFindNextFile($search)
    If @error Then ExitLoop
    If $file <> '.' And $file <> '..' Then
        $file1 = FileGetSize ($file)
        MsgBox(4096, "File:", $file & @CRLF & $file1)
        $totalk = $totalk + $file1/1024;total size in Kb
        $totaln = $totaln + 1
    EndIf

WEnd

FileClose($search);must remember to close the search handle

MsgBox(0,$totaln & " files to transfer","total size = " & $totalk & ' Kb')

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

You don't need arrays to do what you've asked for.

FileChangeDir (@DESKTOPDIR & "\From")
$search = FileFindFirstFile ("*.*")
$totalk = 0;space rquired
$totaln = 0;number of files to copy
While 1

    $file = FileFindNextFile($search)
    If @error Then ExitLoop
    If $file <> '.' And $file <> '..' Then
        $file1 = FileGetSize ($file)
        MsgBox(4096, "File:", $file & @CRLF & $file1)
        $totalk = $totalk + $file1/1024;total size in Kb
        $totaln = $totaln + 1
    EndIf

WEnd

FileClose($search);must remember to close the search handle

MsgBox(0,$totaln & " files to transfer","total size = " & $totalk & ' Kb')

SO basically by moving the msg box out of inside the loop it automatically inciments the values found?

Just so I understand what is happening..

Thanks

Mike

Share this post


Link to post
Share on other sites

SO basically by moving the msg box out of inside the loop it automatically inciments the values found?

Just so I understand what is happening..

Thanks

Mike

No. The msgboxes have nothing to do with incrementing.

I didn't move the msgbox outside of the loop.

I added a new msgbox at the end.

I added FileClose which you had omitted.

I added $totalk to get the total size of all the files. It is incremented by the line $totalk = $totalk +....

I added $totaln to get the total number of files. It is incremented by the line $totaln = $totaln +....

I added an If condition so that the '.' and '..' returns from FileFindNext were ignored.


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

No. The msgboxes have nothing to do with incrementing.

I didn't move the msgbox outside of the loop.

I added a new msgbox at the end.

I added FileClose which you had omitted.

I added $totalk to get the total size of all the files. It is incremented by the line $totalk = $totalk +....

I added $totaln to get the total number of files. It is incremented by the line $totaln = $totaln +....

I added an If condition so that the '.' and '..' returns from FileFindNext were ignored.

After looking at it I can now understand the $totalk and the $totaln but the If statement with the . and .. how do these reference the retiurns from filefindnext

Shedding light on this will help me understand how to rwrite this thing in future....

At this point would I also move to including the Progress on part of the script like the help file?

ProgressOn("Progress Meter", "Increments every second", "0 percent")

For $i = 10 to 100 step 10

sleep(1000)

ProgressSet( $i, $i & " percent")

Next

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

sleep(500)

ProgressOff()

That is from the help file...

Thanks for all your help

Mike

Share this post


Link to post
Share on other sites

After looking at it I can now understand the $totalk and the $totaln but the If statement with the . and .. how do these reference the retiurns from filefindnext

Shedding light on this will help me understand how to rwrite this thing in future....

At this point would I also move to including the Progress on part of the script like the help file?

ProgressOn("Progress Meter", "Increments every second", "0 percent")

For $i = 10 to 100 step 10

sleep(1000)

ProgressSet( $i, $i & " percent")

Next

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

sleep(500)

ProgressOff()

That is from the help file...

Thanks for all your help

Mike

You need to spend more time playing with things and thinking. You can answer these questions yourself, it just takes time, effort, misery, grief, joy, ecstasy, frustration, delight, exhaustion, disappointment, relief sleeplessness, excitement.

To see a variable you can add a consolewrite("$something = " & $something & @CRLF) or have a msgbox.

$file is set to be the returned value from FileFindNext, so when you later look at $file you are looking at the result returned from FileFindNext. Look and see what gets returned each time by adding a msgbox immediately afterwards.

You need to play, try, figure, play, try, figure a lot.

I guess from what you say that you might not understand the progress bar example, so just study it, try to understand it, change something, see what happens, figure out why if it doesn't do what you expect, try something else. But the main thing is that you start with something and you understand exactly what is happening by the time you have finished no matter how long it takes. Being told how to do something isn't learning how to do it.


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

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