Skeletor Posted November 8, 2018 Posted November 8, 2018 Hi All, I want to make my progress bar progress with the amount of File lines read. How would I do this correctly. So far the code below can sometimes run in the middle of the progress bar and state completed.. and other times it can run into the 200%. ;======================================================================== ProgressOn("TITLE", "ACTION") ;======================================================================== For $count = 1 To _FileCountLines($FileRead) Step 1 $string = FileReadLine($FileRead, $count) $value1 = $input[1] $value2 = $input[2] $value3 = $input[3] $value4 = $input[4] $TM = FileWrite("C:\temp\test.txt", $value1 & " " & $value2 & " " & $value3 & " " & $value4 & @CRLF) ProgressSet($count, $count & "%") Next ;======================================================================== ; PROGRESS BAR OFF ;======================================================================== ProgressSet(_FileCountLines($FileRead), "Completed!") Sleep(750) ProgressOff() ;======================================================================== Kind RegardsSkeletor "Coffee: my defense against going postal." Microsoft Office Splash Screen | Basic Notepad Program (Beginner) | Transparent Splash Screen | Full Screen UI
Gianni Posted November 8, 2018 Posted November 8, 2018 .. more or less something like this: ;======================================================================== ProgressOn("TITLE", "ACTION") ;======================================================================== $iRows = _FileCountLines($FileRead) For $count = 1 To $iRows Step 1 $string = FileReadLine($FileRead, $count) $value1 = $input[1] $value2 = $input[2] $value3 = $input[3] $value4 = $input[4] $TM = FileWrite("C:\temp\test.txt", $value1 & " " & $value2 & " " & $value3 & " " & $value4 & @CRLF) $iPercent = Int($count / $iRows * 100) ProgressSet($iPercent, $count & "/" & $iRows & @TAB & "(" & $iPercent & "%)") Next ;======================================================================== ; PROGRESS BAR OFF ;======================================================================== ProgressSet($iPercent, "Completed!") Sleep(750) ProgressOff() ;======================================================================== Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....
Skeletor Posted November 8, 2018 Author Posted November 8, 2018 @Chimp, I took long to reply because I had to test the script. It works 100%. Thanks Chimp... Kind RegardsSkeletor "Coffee: my defense against going postal." Microsoft Office Splash Screen | Basic Notepad Program (Beginner) | Transparent Splash Screen | Full Screen UI
Bilgus Posted September 14, 2019 Posted September 14, 2019 (edited) With Binary.. expandcollapse popup;File read progress bytes #include <FileConstants.au3> #include <WinAPIFiles.au3> Local Const $KB = 1024 Local Const $CHUNKBYTES = 64 * $KB ;64 kb each read Local $sFileName = SelectFile() If Not FileExists($sFileName) Then Exit Local $hFileRead = FileOpen($sFileName, $FO_BINARY) ;open in binary read mode ;file is already open get filesize this way instead of FileGetSize() FileSetPos($hFileRead, 0, $FILE_END) Local $iFileSizeBytes = FileGetPos($hFileRead) Local $iFileSizeKB = Int($iFileSizeBytes / $KB) Local $iRead, $sBinary, $iPercent Local $FileData = "" ;======================================================================== ProgressOn("TITLE", "ACTION", "", Default, Default, $DLG_MOVEABLE) ;======================================================================== $iRead = 0 FileSetPos($hFileRead, $iRead, $FILE_BEGIN) ;Start reading from the pos $iRead in the file ConsoleWrite("Reading " & $iFileSizeBytes - $iRead & " Bytes" & @CRLF) ;Note: Filesize limited by string size limit.. While $iRead < $iFileSizeBytes $iReadChunk = $CHUNKBYTES If $iReadChunk + $iRead > $iFileSizeBytes Then $iReadChunk = $iFileSizeBytes - $iRead $sBinary = FileRead($hFileRead, $iReadChunk) $iRead += @extended If @extended = 0 Or @error Then ExitLoop $FileData &= StringTrimLeft($sBinary, 2) ;remove 0x $iPercent = Int($iRead / $iFileSizeBytes * 100) If $iFileSizeKB > 10 Then ProgressSet($iPercent, Int($iRead / $KB) & "/" & $iFileSizeKB & "KB (" & $iPercent & "%)") Else ProgressSet($iPercent, $iRead & "/" & $iFileSizeBytes & "B (" & $iPercent & "%)") EndIf WEnd $FileData = "0x" & $FileData ;Need put 0x back FileClose($hFileRead) ;Local $sConversionANSI = BinarytoString($FileData, $SB_ANSI) ;Local $sConversionUTF8= BinarytoString($FileData, $SB_UTF8) ConsoleWrite("Writing data to " & @TempDir & "\test.txt" & @CRLF) Local $hFileWrite = FileOpen(@TempDir & "\test.txt", BitOR($FO_OVERWRITE, $FO_BINARY)) FileWrite($hFileWrite, $FileData) FileClose($hFileWrite) ;======================================================================== ; PROGRESS BAR OFF ;======================================================================== Sleep(750) ProgressSet($iPercent, "Completed!") Sleep(750) ProgressOff() ;======================================================================== Func SelectFile() ;From the helpfile ; Create a constant variable in Local scope of the message to display in FileOpenDialog. Local Const $sMessage = "Select a single file of any type." ; Display an open dialog to select a file. Local $sFileOpenDialog = FileOpenDialog($sMessage, @WindowsDir & "\", "All (*.*)", $FD_FILEMUSTEXIST) ;" If @error <> 0 Then ;Display the error message. MsgBox($MB_SYSTEMMODAL, "", "No file was selected.") ;Change the working directory (@WorkingDir) back to the location of the script directory as FileOpenDialog sets it to the last accessed folder. FileChangeDir(@ScriptDir) Else ;Change the working directory (@WorkingDir) back to the location of the script directory as FileOpenDialog sets it to the last accessed folder. FileChangeDir(@ScriptDir) EndIf ConsoleWrite($sFileOpenDialog & @CRLF) Return $sFileOpenDialog EndFunc Edited September 14, 2019 by Bilgus
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now