Page 2 of 2 <12
Topic Options
#157638 - 2006-02-27 03:25 PM Re: Folders sorted by size
BunzyBuddy Offline
Fresh Scripter

Registered: 2006-02-22
Posts: 40
Loc: Amsterdam, Holland
Yes, thats works.
Is there a way to format the output in MB instead of bytes ?
My whole script is formatted with the "FormatNumber" expression while writing results to a textfile.

WRITELINE (1, $item[0] + " " + $item[1] + @CRLF)

Top
#157639 - 2006-02-27 03:55 PM Re: Folders sorted by size
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
Just divide it by 1024.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#157640 - 2006-02-27 05:04 PM Re: Folders sorted by size
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
...and then by 1024 again.
Top
#157641 - 2006-02-27 08:42 PM Re: Folders sorted by size
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
Woops, my bad
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#157642 - 2006-02-28 09:51 AM Re: Folders sorted by size
BunzyBuddy Offline
Fresh Scripter

Registered: 2006-02-22
Posts: 40
Loc: Amsterdam, Holland
When I run my script, I got all homedirs and their sizer. That's good. But is it possible to limit the number of items to, lets say 10 ? So only the top-10 of the biggest folders will be reported ?
Top
#157643 - 2006-02-28 10:09 AM Re: Folders sorted by size
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Yes, just use an index counter.
Top
#157644 - 2006-02-28 10:09 AM Re: Folders sorted by size
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Yes.

How have you tried to do it so far?

Top
#157645 - 2006-02-28 10:10 AM Re: Folders sorted by size
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Also just ask up front what you really want, this is like the 2nd or 3rd request to have it do something different than you originally asked, which is okay, but asking up front and letting us know specifically what you want would save everyone time.
Top
#157646 - 2006-02-28 10:28 AM Re: Folders sorted by size
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
doc, I saved my time by not answering the first questions
_________________________
!

download KiXnet

Top
#157647 - 2006-02-28 11:48 AM Re: Folders sorted by size
BunzyBuddy Offline
Fresh Scripter

Registered: 2006-02-22
Posts: 40
Loc: Amsterdam, Holland
I'm sorry, I thought my firt question was clear:

Quote:

I want to scan the size of the users HomeDirs in our HomeDirs folder, sort all folders by size and write the 3 biggest folders' name and size in a textfile.




So, now I have almost all of it, only the selection of the 10 biggest folders (okay, instead of 3) is missing.

Using counters ? I'm afraid I do not know how to do so. If I did, I wouldn't be asking on this forum, would I?

Top
#157648 - 2006-02-28 12:03 PM Re: Folders sorted by size
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
well, if you have a array having the folders, counter is the thingie inside the brackets.

thus $array[0] would give you the largest.

for $counter=0 to 9
$array[$counter] ?
next

would give you the 10 largest.
_________________________
!

download KiXnet

Top
#157649 - 2006-02-28 12:16 PM Re: Folders sorted by size
BunzyBuddy Offline
Fresh Scripter

Registered: 2006-02-22
Posts: 40
Loc: Amsterdam, Holland
OK, I understand the meaning of $Counter, but I'm not sure where to put in in my script. I've tried serval places without any luck. Could you please tell me where to put int in ?


*********
break on
call 'quicksort.udf'
call 'dirplus.udf'

OPEN (1, "E:\Script\HomeSize @MDAYNO @MONTH @YEAR.txt",5)

$root = dirplus('$HomeDirsLocation','/ad')

dim $folders[ubound($root)]

for $i = 0 to ubound($root)
$n = $root[$i].name
$s = val($root[$i].size)
$folders[$i] = $n,$s
next

$folders = quicksort($folders,1)

For $i = UBound($folders) To 0 Step -1
$item=$folders[$i]
$item[0]+" "+$item[1]+@CRLF
WRITELINE (1, $item[0] + " " + FormatNumber (CDbl($item[1]/1024/1024),0) + " MB" + @CRLF)
Next

**********

Top
#157650 - 2006-02-28 12:19 PM Re: Folders sorted by size
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
well, I already gave you example but here:
For $i = UBound($folders) To 0 Step -1

instead of ubound, do $i = 9
_________________________
!

download KiXnet

Top
#157651 - 2006-02-28 12:29 PM Re: Folders sorted by size
BunzyBuddy Offline
Fresh Scripter

Registered: 2006-02-22
Posts: 40
Loc: Amsterdam, Holland
I'm sorry Jooel, I replaced

For $i = UBound($folders) To 0 Step -1

by

For $i = 9 To 0 Step -1

but this gives me a result of all homedirs sizes of 0MB...

Top
#157652 - 2006-02-28 12:53 PM Re: Folders sorted by size
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Try this:
Code:
$iLimit=UBound($Folders)-9
If $iLimit<9 $iLimit=UBound($Folders) EndIf
For $i = UBound($folders) To $iLimit Step -1
$item=$folders[$i]
$item[0]+" "+$item[1]+@CRLF
$=WriteLine(1, $item[0] + " " + FormatNumber (CDbl($item[1]/1024/1024),0) + " MB" + @CRLF)
Next


Top
#157653 - 2006-02-28 12:59 PM Re: Folders sorted by size
BunzyBuddy Offline
Fresh Scripter

Registered: 2006-02-22
Posts: 40
Loc: Amsterdam, Holland
You are a scripting hero.

Now everything works exactly the way I wanted. Thank you all you guys for your help and patience !

Top
#157654 - 2006-02-28 01:02 PM Re: Folders sorted by size
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
hmm...
sorry for my ignorance.
it wasn't clear to me which way your sorted array was increasing.
specially when you were going it backwards up in the for loop, it got me confused.
_________________________
!

download KiXnet

Top
#157655 - 2006-02-28 01:16 PM Re: Folders sorted by size
BunzyBuddy Offline
Fresh Scripter

Registered: 2006-02-22
Posts: 40
Loc: Amsterdam, Holland
Don't bother, you were all great help. Could not do it without you !
Top
#157656 - 2006-03-23 11:44 AM Re: Folders sorted by size
BunzyBuddy Offline
Fresh Scripter

Registered: 2006-02-22
Posts: 40
Loc: Amsterdam, Holland
Last question:
In my script I'm first scanning all HomeDirs and writing the results to my textfile. After that I'm scanning the GroupsDirs and also writing the results to the textfile. But, when a HomeDirectory's size is bigger than one of the GroupsDirs, it appears in the GroupsDirs result list.

So, is there a command to clear the "cache" after having scanned the Homedirs ?

Top
Page 2 of 2 <12


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 515 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.071 seconds in which 0.025 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org