#169262 - 2006-10-12 12:07 PM
DirPlus results are false
|
BunzyBuddy
Fresh Scripter
Registered: 2006-02-22
Posts: 40
Loc: Amsterdam, Holland
|
I've written a script to scan users homedirectories on size, sort them by size (biggest on top) and write the 10 biggest folders to a textfile. To do this, first DirPlus UDF scannes all folders and QuickSort UDF sorts them out by size, biggest on top.
Problem is that the results are false. It doesn't return the top-10 of biggest folders, but returns 10 folders randomly. Not even the biggest or smalles are mentioned, just random folders witch are sorted by size.
Variable $HomeDirsLocation is defined earlier in my script. The textfile to write to is also already opened earlier.
Code:
BREAK ON call 'quicksort.udf' call 'dirplus.udf'
WRITELINE (1, "Gebruik van de HomeDirs TOP-10" + @CRLF) WRITELINE (1, "------------------------------------" + @CRLF)
$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)
$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] + chr(009) + chr(009) + FormatNumber (CDbl($item[1]/1024/1024),0) + " MB" + @CRLF) NEXT
WRITELINE (1, @CRLF + @CRLF + @CRLF + @CRLF)
I don't understand what I'm doing wrong. Can someone help me please ?
|
Top
|
|
|
|
#169263 - 2006-10-12 12:48 PM
Re: DirPlus results are false
|
Witto
MM club member
Registered: 2004-09-29
Posts: 1828
Loc: Belgium
|
I think this question is about what you are looking for: Folders sorted by size
|
Top
|
|
|
|
#169264 - 2006-10-12 01:16 PM
Re: DirPlus results are false
|
BunzyBuddy
Fresh Scripter
Registered: 2006-02-22
Posts: 40
Loc: Amsterdam, Holland
|
Thanx Witto, but this is my own forum I started when I was starting to write my script. So the solutions people gave me over there are not realy correct. Thanx for your reply anyway
|
Top
|
|
|
|
#169265 - 2006-10-12 01:35 PM
Re: DirPlus results are false
|
Witto
MM club member
Registered: 2004-09-29
Posts: 1828
Loc: Belgium
|
I think the answer Doc gave is working. I tested it here. Code:
If NOT @LOGONMODE Break On Else Break Off EndIf Dim $RC ;$RC = SetOption("Explicit","On") ;$RC = SetOption("NoVarsInStrings","On") ;$RC = SetOption("NoMacrosInStrings","On") ;$RC = SetOption("WrapAtEOL","On")
$root = dirplus('C:\Program Files','/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 Each $item In $folders ; ? $item[0] " " $item[1] ;Next ;For $i = Ubound($folders) To 0 Step -1 For $i = Ubound($folders) To (Ubound($folders)-10) Step -1 $item=$folders[$i] $item[0]+" "+$item[1]+@CRLF Next Function DirPlus($path,optional $Options, optional $f, optional $sfflag) If NOT VarType($f) Dim $f EndIf If NOT VarType($sfflag) Dim $sfflag EndIf Dim $file, $i, $temp, $item, $ex1, $mask,$mask1,$maskArray,$maskarray1, $ex2, $code, $CodeWeight, $targetWeight, $weight, $masktrue Dim $tarray[0] $ex1 = SetOption(Explicit,on) $ex2 = SetOption(NoVarsInStrings,on) $codeWeight = 0 If NOT Exist($path) $temp = SetOption(Explicit,$ex1) $temp = SetOption(NoVarsInStrings,$ex2) Exit @ERROR EndIf If NOT VarType($f) $f = CreateObject("Scripting.FileSystemObject").getfolder($path) EndIf If @ERROR $temp = SetOption(Explicit,$ex1) $temp = SetOption(NoVarsInStrings,$ex2) Exit @ERROR EndIf For Each $temp In Split($options,"/") $temp=Trim($temp) Select Case Left($temp,1) = "s" If NOT VarType($sfflag) If Val(Right($temp,-1)) = 0 $sfflag = -1 Else $sfflag = Val(Right($temp,-1)) EndIf EndIf Case Left($temp,1) = "a" Select Case Right($temp,-1)="d" $codeWeight = $codeWeight + 1 $temp = "if $file.attributes & 16 " ;"if $file.type = 'File Folder' " Case Right($temp,-1)="-d" $codeWeight = $codeWeight + 1 $temp = "if ($file.attributes & 16)=0 " ;"if $file.type <> 'File Folder' " Case Right($temp,-1)="s" $codeWeight = $codeWeight + 1 $temp = "if $file.attributes & 4 " Case Right($temp,-1)="-s" $codeWeight = $codeWeight + 1 $temp = "if ($file.attributes & 4)=0 " Case Right($temp,-1)="h" $codeWeight = $codeWeight + 1 $temp = "if $file.attributes & 2 " Case Right($temp,-1)="-h" $codeWeight = $codeWeight + 1 $temp = "if ($file.attributes & 2)=0 " Case Right($temp,-1)="r" $codeWeight = $codeWeight + 1 $temp = "if $file.attributes & 1 " Case Right($temp,-1)="-r" $codeWeight = $codeWeight + 1 $temp = "if ($file.attributes & 1)=0 " Case Right($temp,-1)="a" $codeWeight = $codeWeight + 1 $temp = "if $file.attributes & 32 " Case Right($temp,-1)="-a" $codeWeight = $codeWeight + 1 $temp = "if ($file.attributes & 32)=0 " EndSelect $code = $temp + "$weight=$weight+1 endif" +@CRLF + $code Case Left($temp,1) = "m" $maskarray = Split(Right($temp,-2),"|") $codeweight = $codeweight + 1 $code = "$masktrue=0 for Each $mask in $maskarray if instr($file.name,$mask) $masktrue=1 " + "EndIf Next If $masktrue $weight=$weight+1 endif" + @CRLF +$code Case Left($temp,1) = "f" $maskarray1 = Split(Right($temp,-2)," ") $codeweight = $codeweight + 1 $code = "$masktrue=0 for Each $mask1 in $maskarray1 if substr($file.name,Instrrev($file.name,'.')+1)" + "=$mask1 $masktrue=1 EndIf Next If $masktrue $weight=$weight+1 endif" + @CRLF +$code EndSelect Next $code = "$weight = 0 $targetWeight = " + $codeweight + @CRLF + $code $code = $code + "if $weight = $targetweight Exit 1 endif" For Each $file In $f.subfolders If Execute($code) $tarray[$i] = $file $i = $i + 1 ReDim preserve $tarray[$i] EndIf If $sfflag $temp = dirplus($file,$options,$file,$sfflag-1) For Each $item In $temp $tarray[$i] = $item $i = $i + 1 ReDim preserve $tarray[$i] Next EndIf Next For Each $file In $f.files If Execute($code) $tarray[$i] = $file $i = $i + 1 ReDim preserve $tarray[$i] EndIf Next If $i ReDim preserve $tarray[$i-1] $i=0 Else $tarray = 0 EndIf $dirplus = $tarray $temp = SetOption(Explicit,$ex1) $temp = SetOption(NoVarsInStrings,$ex2) Exit @ERROR EndFunction Function quicksort($a, optional $indexcol ) ;$a array to be sorted ;$indexcol index of subitem to sort on ;$LowerIndexStack lower index stack ;$UpperIndexStack upper index stack ;$StackPointer stack pointer ;$LowerIndex lower index ;$UpperIndex upper index ;$Pivot value of pivot ;$TempSwappingValue temp variable for swapping elements ;$index stores either lower or upper index of unsorted segment of the array ;$i counter moving from lower index to the right ;$j counter moving from upper index to the left ;$LowerItem value to compare with Dim $StackSize, $StackIncr $StackSize = 8 $StackIncr = $StackSize Dim $LowerIndexStack[$StackSize],$UpperIndexStack[$StackSize] Dim $StackPointer, $LowerIndex, $UpperIndex, $Pivot, $TempSwappingValue, $index, $i, $j, $LowerItem Dim $ExitLoop If $indexcol $indexcol = CStr($indexcol) If indexcol < 0 $indexcol = 0 EndIf Else $indexcol = 0 EndIf $LowerIndexStack[0]=0 $UpperIndexStack[0]=Ubound($a) $StackPointer=0 While $StackPointer >= 0 $LowerIndex=$LowerIndexStack[$StackPointer] $UpperIndex=$UpperIndexStack[$StackPointer] While $LowerIndex < $UpperIndex $Pivot=$LowerIndex+($UpperIndex-$LowerIndex)/2 $TempSwappingValue=$a[$LowerIndex] $A[$LowerIndex]=$A[$Pivot] $A[$Pivot]=$TempSwappingValue $i=$LowerIndex+1 $j=$UpperIndex $ExitLoop=0 Do $LowerItem = QuickSortItem( $A[$LowerIndex],$indexcol ) While ($i<$j) AND ( QuickSortItem( $A[$i],$indexcol ) < $LowerItem) $i=$i+1 Loop While ($j>=$i) AND ($LowerItem < QuickSortItem( $A[$j],$indexcol )) $j=$j-1 Loop If $i>=$j $ExitLoop=1 Else $TempSwappingValue=$A[$i] $A[$i]=$A[$j] $A[$j]=$TempSwappingValue $j=$j-1 $i=$i+1 EndIf Until $ExitLoop=1 $TempSwappingValue=$a[$LowerIndex] $a[$LowerIndex]=$a[$j] $a[$j]=$TempSwappingValue $index=$j If $index - $LowerIndex <= $UpperIndex - $index If $index+1 < $UpperIndex If $StackPointer>$StackSize $StackSize = $StackSize + $StackIncr ReDim preserve $LowerIndexStack[$StackSize] ReDim preserve $UpperIndexStack[$StackSize] EndIf $LowerIndexStack[$StackPointer]=$index+1 $UpperIndexStack[$StackPointer]=$UpperIndex $StackPointer=$StackPointer+1 EndIf $UpperIndex=$index-1 Else If $index-1 > $LowerIndex If $StackPointer>$StackSize $StackSize = $StackSize + $StackIncr ReDim preserve $LowerIndexStack[$StackSize] ReDim preserve $UpperIndexStack[$StackSize] EndIf $LowerIndexStack[$StackPointer]=$LowerIndex $UpperIndexStack[$StackPointer]=$index-1 $StackPointer=$StackPointer+1 EndIf $LowerIndex=$index+1 EndIf Loop $StackPointer=$StackPointer-1 Loop $quicksort=$a EndFunction Function QuickSortItem( $value, $index ) If VarType($value) & 8192 If ($index <= Ubound($value)) $QuickSortItem = $value[$index] Else $QuickSortItem = "" EndIf Else $QuickSortItem = $value EndIf EndFunction
|
Top
|
|
|
|
#169266 - 2006-10-12 01:48 PM
Re: DirPlus results are false
|
BunzyBuddy
Fresh Scripter
Registered: 2006-02-22
Posts: 40
Loc: Amsterdam, Holland
|
I just tried that code, but still the results are false. The biggest HomeDir according to the results is 649 Mb, while there are some others over 1Gb !! I also tried the script running on c:\Program Files, these results are correct ! Could it be a Security rights problem ? I'm running the script with Domain Administrator rights !
When I run the script on the GroupsDirectories, results are also false. I've no restriction on accessing any GroupsDirectory or subfolder ! I don't get it...
|
Top
|
|
|
|
#169268 - 2006-10-12 02:07 PM
Re: DirPlus results are false
|
BunzyBuddy
Fresh Scripter
Registered: 2006-02-22
Posts: 40
Loc: Amsterdam, Holland
|
Users do not have rights to change NTFS security. But I just found out that there's indeed a problem with access rights for domain Administrators. Stupid stupid stupid !!
Thanx for your help Witto !
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 248 anonymous users online.
|
|
|