How to shift/set column B's values in front of column A in ListView? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Sabestian Caine
Posts: 528
Joined: 12 Apr 2015, 03:53

How to shift/set column B's values in front of column A in ListView?

03 Aug 2020, 12:15

Hello

I am trying to retrieve the size of each folder in KB and MB and for it i made this script

Code: Select all

  SetBatchLines, -1  ; Make the operation run at maximum speed.
   Gui, Add, ListView, Grid r40 w1000, Name|KB|MB|
  
 Loop, D:\*.*,1
{
      dd.= A_LoopFileFullPath "`n"
        LV_Add("", A_LoopFileName, FolderSizeKB) 
      }
      Loop, Parse, dd, `n
      {
         FolderSizeKB = 0
         Loop, Files, %A_LoopField%\*.*, R

    FolderSizeKB += %A_LoopFileSizeKB%
     LV_Add("", "", FolderSizeKB) 

}
       gui, show
Everything is almost fine, but the problem is this-
03_08_20 @10_37_49.PNG
03_08_20 @10_37_49.PNG (47.1 KiB) Viewed 2275 times
In the above image you can see that the size of file/folder are not showing in the front of file/folder, while it is showing beneath file/folder. I want that all the rows of column KB should be shifted in front of column NAME. Please tell me how to solve this problem.

Thanks a lot..
I don't normally code as I don't code normally.
User avatar
boiler
Posts: 16951
Joined: 21 Dec 2014, 02:44

Re: How to shift/set column B's values in front of column A in ListView?  Topic is solved

03 Aug 2020, 12:50

You can do it in a nested loop to make it simpler. You need to have all the data and add the row. If you add a row with the folder name and later add another row with the folder isze, of course it will just add a row and not replace what's in existing rows since you did nothing to specify existing row numbers. Also, it leads to very inaccurate totals if you sum KB and MB numbers from individual files because the rounding errors accumulate and you'll find the KB totals and MB totals will often look very much different. Just use bytes to sum and divide by 1024 for each level (apparently Windows uses 1024 while some have gone to 1000).

Code: Select all

SetBatchLines, -1  ; Make the operation run at maximum speed.
Gui, Add, ListView, Grid r40 w1000, Name|KB|MB|
  
Loop, Files, D:\*.*, D
{
	SplitPath, A_LoopFileFullPath, Folder
	FolderSize := 0
	Loop, Files, %A_LoopFileFullPath%\*.*, R
	    FolderSize += A_LoopFileSize
	LV_Add("", Folder, Round(FolderSize / 1024), Round(FolderSize / 1024 / 1024)) 
}
LV_ModifyCol() ; auto-size column widths
Gui, Show
return

GuiClose:
ExitApp
User avatar
Sabestian Caine
Posts: 528
Joined: 12 Apr 2015, 03:53

Re: How to shift/set column B's values in front of column A in ListView?

04 Aug 2020, 11:59

boiler wrote:
03 Aug 2020, 12:50
You can do it in a nested loop to make it simpler. You need to have all the data and add the row. If you add a row with the folder name and later add another row with the folder isze, of course it will just add a row and not replace what's in existing rows since you did nothing to specify existing row numbers. Also, it leads to very inaccurate totals if you sum KB and MB numbers from individual files because the rounding errors accumulate and you'll find the KB totals and MB totals will often look very much different. Just use bytes to sum and divide by 1024 for each level (apparently Windows uses 1024 while some have gone to 1000).

Code: Select all

SetBatchLines, -1  ; Make the operation run at maximum speed.
Gui, Add, ListView, Grid r40 w1000, Name|KB|MB|
  
Loop, Files, D:\*.*, D
{
	SplitPath, A_LoopFileFullPath, Folder
	FolderSize := 0
	Loop, Files, %A_LoopFileFullPath%\*.*, R
	    FolderSize += A_LoopFileSize
	LV_Add("", Folder, Round(FolderSize / 1024), Round(FolderSize / 1024 / 1024)) 
}
LV_ModifyCol() ; auto-size column widths
Gui, Show
return

GuiClose:
ExitApp


Thanks a lot boiler for your great guidance and help... Your codes are working great. But, they are showing the size of folders only. I mean if there are few files in D:\ then they are not listing them in listview. So i added few lines of codes more to show all files of D:\ too in listview. here are final codes-

Code: Select all

  Gui, +resize
Gui,Font, s10, Arial
SetBatchLines, -1  ; Make the operation run at maximum speed.
Gui, Add, ListView, Grid Sort r30 w1000, Name|KB|MB|GB|
  
Loop, Files, %o%\*.*, D
{
	SplitPath, A_LoopFileFullPath, Folder
	FolderSize := 0
	Loop, Files, %A_LoopFileFullPath%\*.*, R
	    FolderSize += A_LoopFileSize
	LV_Add("", Folder, Round(FolderSize / 1024), Round(FolderSize / 1024 / 1024), Round(FolderSize / 1024 / 1024 / 1024)) 
}
;~ LV_ModifyCol() ; auto-size column widths

Loop, %o%\*.*
{
    LV_Add("", A_LoopFileName, A_LoopFileSizeKB, A_LoopFileSizeMB, A_LoopFileSizeKB/1024/1024)

}
LV_ModifyCol()
LV_ModifyCol(2, "Integer")
LV_ModifyCol(2, "SortDesc")
Gui, Show
return

GuiClose:
gui, destroy
I don't normally code as I don't code normally.
User avatar
boiler
Posts: 16951
Joined: 21 Dec 2014, 02:44

Re: How to shift/set column B's values in front of column A in ListView?

04 Aug 2020, 22:45

Sabestian Caine wrote:
04 Aug 2020, 11:59
Your codes are working great. But, they are showing the size of folders only. I mean if there are few files in D:\ then they are not listing them in listview.
I did that because you said this:
Sabestian Caine wrote:
03 Aug 2020, 12:15
I am trying to retrieve the size of each folder in KB and MB and for it i made this script
User avatar
Sabestian Caine
Posts: 528
Joined: 12 Apr 2015, 03:53

Re: How to shift/set column B's values in front of column A in ListView?

05 Aug 2020, 10:40

boiler wrote:
04 Aug 2020, 22:45
Sabestian Caine wrote:
04 Aug 2020, 11:59
Your codes are working great. But, they are showing the size of folders only. I mean if there are few files in D:\ then they are not listing them in listview.
I did that because you said this:
Sabestian Caine wrote:
03 Aug 2020, 12:15
I am trying to retrieve the size of each folder in KB and MB and for it i made this script

oh... it was my mistake... Ok, Thanks a lot brother...you are really great helper.... :bravo:
I don't normally code as I don't code normally.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee, inseption86, jaka1 and 340 guests