Sign in to follow this  
Followers 0
AzKay

File Organizer - Progress Bar? Any ideas?

8 posts in this topic

CODE
#include <File.au3>
#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("File Organiser", 179, 66, 666, 119, _
BitOR($WS_MINIMIZEBOX,$WS_CAPTION,$WS_GROUP,$WS_BORDER,$WS_CLIPSIBLINGS), _
BitOR($WS_EX_TOOLWINDOW,$WS_EX_TOPMOST,$WS_EX_WINDOWEDGE))
$Extension = GUICtrlCreateInput(".au3", 1, 3, 41, 17)
$Function = GUICtrlCreateButton("Function", 46, 3, 91, 17, 0)
$Progress = GUICtrlCreateProgress(1, 48, 177, 17)
$About = GUICtrlCreateButton("?", 140, 3, 17, 17, 0)
$Exit = GUICtrlCreateButton("X", 160, 3, 17, 17, 0)
$Backup = GUICtrlCreateRadio("Backup", 16, 24, 57, 17)
$Move = GUICtrlCreateRadio("Move", 96, 24, 49, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
$msg = GUIGetMsg()
Switch $msg
    Case $Function
        If GUICtrlRead($Backup) = $GUI_CHECKED Then _Backup()
        If GUICtrlRead($Move) = $GUI_CHECKED Then _Move()
    Case $Exit
        Exit
    Case $About
        MsgBox(0, "About", "")
EndSwitch
WEnd

Func _Backup()
MsgBox(0, "", "ok")
;DirCreate(@DesktopDir & "\Desktop\au3Files")
Dim $aRecords, $szDrive, $szDir, $szFName, $szExt
$PathSplit = @HomeDrive & "\*" & GUICtrlRead($Extension)
$PID = Run(@Comspec & " /c dir /b /s /a " & $PathSplit, "", @SW_HIDE, 6)
If FileExists("Temp.txt") Then FileDelete("Temp.txt")
$File = FileOpen("Temp.txt", 1)
$oProgress = 0

While 1
$oPID = StdoutRead($PID)
If @Error Then ExitLoop
FileWrite($File, $oPID)
GUICtrlSetData($Progress, $oProgress)
$oProgress = $oProgress + 1
WEnd
FileClose($File)
MsgBox(0, "About", "Part 1 Of 2 Done")

;If Not _FileReadToArray("Temp.txt", $aRecords) Then
;   MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
;   Exit
;EndIf

;For $x = 1 to $aRecords[0]
;    If $aRecords[$x] = "" Then ContinueLoop
;    ConsoleWrite($aRecords[$x] & @CRLF)
;    $Path = _PathSplit($aRecords[$x], $szDrive, $szDir, $szFName, $szExt)
;    If IsArray($Path) Then
;        If $szExt = ".bmp" Or $szExt = ".jpg" Or $szExt = ".jpeg" Or $szExt = ".jpg" Or $szExt = ".gif" Or $szExt = ".png" Then
;            FileCopy($aRecords[$x], @MyDocumentsDir & "\My Pictures")
;            If @Error Then FileCopy($aRecords[$x], @MyDocumentsDir & "\My Pictures\" & $szFName & "_" & Random(0, 1000, 1) & $szExt)
;        EndIf
;        If $szExt = ".au3" Then
;            FileCopy($aRecords[$x], @DesktopDir & "\Desktop\au3Files\" & $szFName & $szExt)
;            If @Error Then
;                FileCopy($aRecords[$x], @DesktopDir & "\Desktop\au3Files\" & $szFName & "_" & Random(0, 10000, 1) & $szExt)
;            EndIf
;        EndIf
;    EndIf
;Next
FileDelete("Temp.txt")
EndFunc

Func _Move()
DirCreate(@DesktopDir & "\Desktop\au3Files")
Dim $aRecords, $szDrive, $szDir, $szFName, $szExt
$PathSplit = @HomeDrive & "\*" & GUICtrlRead($Extension)
$PID = Run(@Comspec & " /c dir /b /s /a " & $PathSplit, "", @SW_HIDE, 6)
If FileExists("Temp.txt") Then FileDelete("Temp.txt")
$File = FileOpen("Temp.txt", 1)
$oProgress = 0

While 1
$oPID = StdoutRead($PID)
If @Error Then ExitLoop
FileWrite($File, $oPID)
GUICtrlSetData($Progress, $oProgress)
$oProgress = $oProgress + 1
WEnd
FileClose($File)
MsgBox(0, "About", "Part 1 Of 2 Done")

;If Not _FileReadToArray("Temp.txt", $aRecords) Then
;   MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
;   Exit
;EndIf

;For $x = 1 to $aRecords[0]
;    If $aRecords[$x] = "" Then ContinueLoop
;    ConsoleWrite($aRecords[$x] & @CRLF)
;    $Path = _PathSplit($aRecords[$x], $szDrive, $szDir, $szFName, $szExt)
;    If IsArray($Path) Then
;        If $szExt = ".bmp" Or $szExt = ".jpg" Or $szExt = ".jpeg" Or $szExt = ".jpg" Or $szExt = ".gif" Or $szExt = ".png" Then
;            FileMove($aRecords[$x], @MyDocumentsDir & "\My Pictures")
;            If @Error Then FileMove($aRecords[$x], @MyDocumentsDir & "\My Pictures\" & $szFName & "_" & Random(0, 1000, 1) & $szExt)
;        EndIf
;        If $szExt = ".au3" Then
;            FileMove($aRecords[$x], @DesktopDir & "\Desktop\au3Files\" & $szFName & $szExt)
;            If @Error Then
;                FileCopy($aRecords[$x], @DesktopDir & "\Desktop\au3Files\" & $szFName & "_" & Random(0, 10000, 1) & $szExt)
;            EndIf
;        EndIf
;    EndIf
;Next
FileDelete("Temp.txt")
EndFunc

Basically, I need a way for the progress bar to update, Though, because the progress bar is 1 to 100, this wont work, because, it gets to 100 then then you dont see it update any more, since the progress bar is maxed out. How would I have this in proportion with what im doing?


# MY LOVE FOR YOU... IS LIKE A TRUCK- #

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Basically, I need a way for the progress bar to update, Though, because the progress bar is 1 to 100, this wont work, because, it gets to 100 then then you dont see it update any more, since the progress bar is maxed out. How would I have this in proportion with what im doing?

Well you can use a formula like (Steps #/Total Steps #) * 100. I don't know what your script is about, but you will need to know how many file it going to organize and applyed to the formula.

Let say that your script it going to organize 250 files.

This what I use with autoit: Int(($Steps/250) * 100)

Edited by Danny35d

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites

Except, I dont know how many files.


# MY LOVE FOR YOU... IS LIKE A TRUCK- #

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Except, I dont know how many files.

It is impossible to help you without a source code. You can look at DirGetSize and used flag 1 which return an array with the file count and dir count.

Help file is your best friend...

again without a piece of code, this is just a guessing game.

Edit:

Sorry I didn't notice the code on post #1. I will play with your code and let you know what you can do.

Edited by Danny35d

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites

This should give you what you want or at least get you start it.

Func _Backup()
    Dim $aRecords
    Local $sSourcePath = @HomeDrive
    Local $sTartgetPath = @MyDocumentsDir & '\My Pictures'  
    
    $aRecords = _FileListToArray($sSourcePath, '*' & GUICtrlRead($Extension), 1)
    If (Not IsArray($aRecords)) and (@Error=1) Then
        MsgBox (0,"","No Files\Folders Found.")
        Return
    EndIf
    
    For $x = 1 to $aRecords[0]
        GUICtrlSetData($Progress, Int(($x/$aRecords[0]) * 100))
        FileCopy($sSourcePath & '\' & $aRecords[$x], $sTartgetPath & '\' & $aRecords[$x], 9)
    Next
    GUICtrlSetData($Progress, 0)
EndFunc

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites

Thanks, Ill try it out, Though, I was hoping for a progress for the first part ;) the search part.


# MY LOVE FOR YOU... IS LIKE A TRUCK- #

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

...Though, I was hoping for a progress for the first part :lmao: the search part.

You could peek with StdoutRead, but you do need to know the length of the peek to finish, so it is also unknown. An idea is to use an edit control to scroll the StdoutRead string to show continue search flow. You can show your progress control as paused while the search is showing the edit control output.

;)

Edited by MHz

Share this post


Link to post
Share on other sites

Yeah, I am using the StdoutRead() ;), But yeah, Thats what I needed, a way to find out how many files. I guess ill have to just have it write to its own console.


# MY LOVE FOR YOU... IS LIKE A TRUCK- #

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