AwAke Posted September 5, 2008 Share Posted September 5, 2008 Hello I have a basic gui which searches the programs folder, and writes each file into the listview aswell as its size. But ive come across a problem and have no idea how I could solve it. I would like it if the tab were clicked it would sort it in order of size. If anyone can point me in the right direction without doing most of the work i'd deeply appreciate it. Thx in advance. Here is the code: expandcollapse popup#include <GUIConstantsEx.au3> #include <ButtonConstants.au3> #include <WindowsConstants.au3> #Include <File.au3> #Include <Array.au3> Global $gui = GUICreate("test", 370, 130, 500, 500, -1) GUISetState(@SW_SHOW) $Filesize = GUICtrlCreateButton("File Size", 313, 10) While 1 $msg = GUIGetMsg() Select Case $msg = $Filesize _fileSize() GUISetState(@SW_ENABLE, $gui) GUISetState(@SW_RESTORE, $gui) Case $msg = $GUI_EVENT_CLOSE ExitLoop EndSelect Wend Func _fileSize() GUISetState(@SW_DISABLE, $gui) Local $button, $item1, $item2, $item3, $input1, $msg Local $listview Local $child = GUICreate("test", 220, 250, 100, 200, -1, -1, $gui) Local $listview = GUICtrlCreateListView("File Name | Size", 10, 10, 200, 200);,$LVS_SORTDESCENDING) Local $go = GuiCtrlCreateButton("Search", 50, 218) Local $close = GuiCtrlCreateButton("Close", 130, 218) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $go $search = FileFindFirstFile(@ProgramFilesDir & "\*.*") If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") ExitLoop EndIf Local $avArray[1] Local $asArray[1] Local $Array[1] While 1 $file = FileFindNextFile($search) $path = @ProgramFilesDir & "\" & $file If @error Then ExitLoop $size = DirGetSize($path) $size = Round($size/1024/1024) _ArrayAdd($asArray, $file) _ArrayAdd($avArray, $size) $item1 = GUICtrlCreateListViewItem($file &"|"&$size& "MB's", $listview) WEnd FileClose($search) Case $msg = $close GUIDelete($child) ExitLoop Case $msg = $GUI_EVENT_CLOSE GUIDelete($child) ExitLoop EndSelect Wend EndFunc ;==>Example Link to comment Share on other sites More sharing options...
Szhlopp Posted September 5, 2008 Share Posted September 5, 2008 Hello I have a basic gui which searches the programs folder, and writes each file into the listview aswell as its size. But ive come across a problem and have no idea how I could solve it. I would like it if the tab were clicked it would sort it in order of size. If anyone can point me in the right direction without doing most of the work i'd deeply appreciate it. Thx in advance. Here is the code: expandcollapse popup#include <GUIConstantsEx.au3> #include <ButtonConstants.au3> #include <WindowsConstants.au3> #Include <File.au3> #Include <Array.au3> Global $gui = GUICreate("test", 370, 130, 500, 500, -1) GUISetState(@SW_SHOW) $Filesize = GUICtrlCreateButton("File Size", 313, 10) While 1 $msg = GUIGetMsg() Select Case $msg = $Filesize _fileSize() GUISetState(@SW_ENABLE, $gui) GUISetState(@SW_RESTORE, $gui) Case $msg = $GUI_EVENT_CLOSE ExitLoop EndSelect Wend Func _fileSize() GUISetState(@SW_DISABLE, $gui) Local $button, $item1, $item2, $item3, $input1, $msg Local $listview Local $child = GUICreate("test", 220, 250, 100, 200, -1, -1, $gui) Local $listview = GUICtrlCreateListView("File Name | Size", 10, 10, 200, 200);,$LVS_SORTDESCENDING) Local $go = GuiCtrlCreateButton("Search", 50, 218) Local $close = GuiCtrlCreateButton("Close", 130, 218) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $go $search = FileFindFirstFile(@ProgramFilesDir & "\*.*") If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") ExitLoop EndIf Local $avArray[1] Local $asArray[1] Local $Array[1] While 1 $file = FileFindNextFile($search) $path = @ProgramFilesDir & "\" & $file If @error Then ExitLoop $size = DirGetSize($path) $size = Round($size/1024/1024) _ArrayAdd($asArray, $file) _ArrayAdd($avArray, $size) $item1 = GUICtrlCreateListViewItem($file &"|"&$size& "MB's", $listview) WEnd FileClose($search) Case $msg = $close GUIDelete($child) ExitLoop Case $msg = $GUI_EVENT_CLOSE GUIDelete($child) ExitLoop EndSelect Wend EndFunc ;==>ExampleoÝ÷ Ûú®¢×z·¢²Ø^r^"ë{ax׫tér±«¢+Ù}U% Ñɱ1¥ÍÑY¥Ý}I¥ÍÑÉM½ÉÑ ±± ¬ ÀÌØí¡1¥ÍÑ5¥¸¤()]¡¥±Ä((MÝ¥Ñ U%Ñ5Í ¤( ÍÀÌØíU%}Y9Q} 1=M(á¥Ð( ÍÀÌØí¡1¥ÍÑ5¥¸(}U% Ñɱ1¥ÍÑY¥Ý}M½ÉÑ%ÑµÌ ÀÌØí¡1¥ÍÑ5¥¸°U% ÑɱÑMÑÑ ÀÌØí¡1¥ÍÑ5¥¸¤ RegEx/RegExRep Tester!Nerd Olympics - Community App!Login UDFMemory UDF - "Game.exe+753EC" - CE pointer to AU3Password Manager W/ SourceDataFiler - Include files in your au3!--- Was I helpful? Click the little green '+' Link to comment Share on other sites More sharing options...
AwAke Posted September 5, 2008 Author Share Posted September 5, 2008 (edited) Hey sorry for the consistent reply's for help but ive taken regard for what you have said. However im unsure how I would use it, and where to place it. After clicking the File Search button and the gui opening then clicking the search button, the program comes to a halt and chrashes. What I have atm is: expandcollapse popup#include <GUIConstantsEx.au3> #include <ButtonConstants.au3> #include <WindowsConstants.au3> #Include <File.au3> #Include <Array.au3> #include <GuiListView.au3> Global $gui = GUICreate("test", 370, 130, 500, 500, -1) GUISetState(@SW_SHOW) $Filesize = GUICtrlCreateButton("File Size", 313, 10) While 1 $msg = GUIGetMsg() Select Case $msg = $Filesize _fileSize() GUISetState(@SW_ENABLE, $gui) GUISetState(@SW_RESTORE, $gui) Case $msg = $GUI_EVENT_CLOSE ExitLoop EndSelect Wend Func _fileSize() GUISetState(@SW_DISABLE, $gui) Local $button, $item1, $item2, $item3, $input1, $msg, $size, $hlistView Local $listview Local $child = GUICreate("test", 220, 250, 100, 200, -1, -1, $gui) Local $listview = GUICtrlCreateListView("File Name | Size", 10, 10, 200, 200);,$LVS_SORTDESCENDING) Local $go = GuiCtrlCreateButton("Search", 50, 218) Local $close = GuiCtrlCreateButton("Close", 130, 218) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $go $search = FileFindFirstFile(@ProgramFilesDir & "\*.*") If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") ExitLoop EndIf Local $avArray[1] Local $asArray[1] Local $Array[1] While 1 $file = FileFindNextFile($search) $path = @ProgramFilesDir & "\" & $file If @error Then ExitLoop $size = DirGetSize($path) Global $size = Round($size/1024/1024) _ArrayAdd($asArray, $file) _ArrayAdd($avArray, $size) $hListView = GUICtrlCreateListViewItem($file &"|"&$size& "MB's", $listview) WEnd FileClose($search) _GUICtrlListView_RegisterSortCallBack($hListView) Case $msg = $hListView _GUICtrlListView_SortItems($hListView, GUICtrlGetState($hListView)) Case $msg = $close GUIDelete($child) ExitLoop Case $msg = $GUI_EVENT_CLOSE GUIDelete($child) ExitLoop EndSelect Wend EndFunc ;==>Example Edited September 5, 2008 by AwAke Link to comment Share on other sites More sharing options...
Szhlopp Posted September 5, 2008 Share Posted September 5, 2008 Np. Here: expandcollapse popup#include <GUIConstantsEx.au3> #include <ButtonConstants.au3> #include <WindowsConstants.au3> #Include <File.au3> #Include <Array.au3> #include <GuiListView.au3> Global $gui = GUICreate("test", 370, 130, 500, 500, -1) GUISetState(@SW_SHOW) $Filesize = GUICtrlCreateButton("File Size", 313, 10) While 1 $msg = GUIGetMsg() Select Case $msg = $Filesize _fileSize() GUISetState(@SW_ENABLE, $gui) GUISetState(@SW_RESTORE, $gui) Case $msg = $GUI_EVENT_CLOSE ExitLoop EndSelect Wend Func _fileSize() GUISetState(@SW_DISABLE, $gui) Local $button, $item1, $item2, $item3, $input1, $msg, $size Local $listview Local $child = GUICreate("test", 220, 250, 100, 200, -1, -1, $gui) Local $listview = GUICtrlCreateListView("File Name | Size", 10, 10, 200, 200);,$LVS_SORTDESCENDING) _GUICtrlListView_RegisterSortCallBack($listview) Local $go = GuiCtrlCreateButton("Search", 50, 218) Local $close = GuiCtrlCreateButton("Close", 130, 218) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $go $search = FileFindFirstFile(@ProgramFilesDir & "\*.*") If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") ExitLoop EndIf Local $avArray[1] Local $asArray[1] Local $Array[1] While 1 $file = FileFindNextFile($search) $path = @ProgramFilesDir & "\" & $file If @error Then ExitLoop $size = DirGetSize($path) $size = Round($size/1024/1024) _ArrayAdd($asArray, $file) _ArrayAdd($avArray, $size) $item1 = GUICtrlCreateListViewItem($file &"|"&$size& "MB's", $listview) WEnd FileClose($search) Case $msg = $listview _GUICtrlListView_SortItems($listview, GUICtrlGetState($listview)) Case $msg = $close GUIDelete($child) ExitLoop Case $msg = $GUI_EVENT_CLOSE GUIDelete($child) ExitLoop EndSelect Wend EndFunc ;==>Example RegEx/RegExRep Tester!Nerd Olympics - Community App!Login UDFMemory UDF - "Game.exe+753EC" - CE pointer to AU3Password Manager W/ SourceDataFiler - Include files in your au3!--- Was I helpful? Click the little green '+' Link to comment Share on other sites More sharing options...
AwAke Posted September 5, 2008 Author Share Posted September 5, 2008 Ah thanks for the help, I really appreciate it. However with the recent code you have given me when sorting it doesnt seem to sort properly, some files which are bigger in size appear further down the list with smaller file sizes above it. Sorry if this causes you any hassle. You have my apologies. Link to comment Share on other sites More sharing options...
AwAke Posted September 5, 2008 Author Share Posted September 5, 2008 (edited) After looking again it seems as though it only takes count for the first digit. For e.g; Adobe | 89MB's Google | 23MB's GArena | 8MB's Will probably be sorted as; GArena | 8MB's Adobe | 89MB's Google | 23MB's Thx once again for the help you have given me. Edited September 5, 2008 by AwAke Link to comment Share on other sites More sharing options...
AwAke Posted September 6, 2008 Author Share Posted September 6, 2008 Bump! (Sorry for being impatient ) Link to comment Share on other sites More sharing options...
rasim Posted September 6, 2008 Share Posted September 6, 2008 Bump! (Sorry for being impatient )If your ListView control not have images use a _GUICtrlListView_SimpleSort() function Link to comment Share on other sites More sharing options...
AwAke Posted September 6, 2008 Author Share Posted September 6, 2008 (edited) I took into account for what you said Rasim, yet the help file looks way too complicated. Ive messed about with the function and searched various times over the forum for an easier way to do this. However I may just be over complimenting things. This is what I have so far: expandcollapse popup#include <GUIConstantsEx.au3> #include <ButtonConstants.au3> #include <WindowsConstants.au3> #Include <File.au3> #Include <Array.au3> #include <GuiListView.au3> Global $gui = GUICreate("test", 370, 130, 500, 500, -1) GUISetState(@SW_SHOW) $Filesize = GUICtrlCreateButton("File Size", 313, 10) While 1 $msg = GUIGetMsg() Select Case $msg = $Filesize _fileSize() GUISetState(@SW_ENABLE, $gui) GUISetState(@SW_RESTORE, $gui) Case $msg = $GUI_EVENT_CLOSE ExitLoop EndSelect Wend Func _fileSize() GUISetState(@SW_DISABLE, $gui) Local $button, $item1, $item2, $item3, $input1, $msg, $size, $hListView Local $listview Local $child = GUICreate("test", 220, 250, 100, 200, -1, -1, $gui) Local $hlistview = GUICtrlCreateListView("File Name | Size", 10, 10, 200, 200);,$LVS_SORTDESCENDING) _GUICtrlListView_RegisterSortCallBack($hlistview) Local $go = GuiCtrlCreateButton("Search", 50, 218) Local $close = GuiCtrlCreateButton("Close", 130, 218) GUISetState() Global $hWnd, $iMsg, $iwParam, $ilParam #forceref $hWnd, $iMsg, $iwParam Local $hWndFrom, $iCode, $tNMHDR, $hWndListView, $tInfo, $iCol $hWndListView = $hListView If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView) Global $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) Global $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) Global $iCode = DllStructGetData($tNMHDR, "Code") While 1 $msg = GUIGetMsg() Select Case $msg = $go $search = FileFindFirstFile(@ProgramFilesDir & "\*.*") If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") ExitLoop EndIf Local $avArray[1] Local $asArray[1] Local $Array[1] While 1 $file = FileFindNextFile($search) $path = @ProgramFilesDir & "\" & $file If @error Then ExitLoop $size = DirGetSize($path) $size = Round($size/1024/1024) _ArrayAdd($asArray, $file) _ArrayAdd($avArray, $size) $item1 = GUICtrlCreateListViewItem($file &"|"&$size& "MB's", $hlistview) WEnd FileClose($search) Case $msg = $hlistview $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam) $iCol = _GUICtrlListView_GetColumnCount($hListView) Dim $B_DESCENDING[$iCol] For $i = 0 To $iCol - 1 $B_DESCENDING[$i] = True ; false = ascending, true = descending Next _GUICtrlListView_SimpleSort($hWndListView, $B_DESCENDING, DllStructGetData($tInfo, "SubItem")) Case $msg = $close GUIDelete($child) ExitLoop Case $msg = $GUI_EVENT_CLOSE GUIDelete($child) ExitLoop EndSelect Wend EndFunc ;==>Example Edited September 6, 2008 by AwAke Link to comment Share on other sites More sharing options...
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