#108657 - 2003-11-21 08:24 PM
Count subdirectorys not include files
|
@lejo @rias
Starting to like KiXtart
Registered: 2003-09-02
Posts: 100
Loc: Medellin, Colombia
|
Hi, I need count a subdirectorys but not the files that contain a directory. for ex: c:\progfil\tiv\mus\ c:\progfil\tiv\mas\ c:\progfil\tiv\mes\ c:\progfil\tiv\cfg.ini c:\progfil\tiv\read.txt
count of subdirs = 3
I use this script
Code:
Function dirlist($dirname, optional $options) Dim $filename, $counter, $filepath, $mask Dim $list, $sublist, $subcounter
$counter=-1
$dirname=Trim($dirname) If $dirname='' $dirname=@CURDIR EndIf If Right($dirname,1)='\' $dirname=Left($dirname,Len($dirname)-1) EndIf If GetFileAttr($dirname) & 16 $mask='*.*' Else $mask=SubStr($dirname,InStrRev($dirname,'\')+1) $dirname=Left($dirname,Len($dirname)-Len($mask)-1) EndIf
ReDim $list[10] $filename=Dir($dirname+'\'+$mask) While $filename<>'' AND @ERROR=0 If $filename<>'.' AND $filename<>'..' Select Case (GetFileAttr($dirname+'\'+$filename) & 16) If $options & 1 $counter=$counter+1 If $options & 2 $list[$counter]=$dirname+'\'+$filename+'\' Else $list[$counter]=$filename+'\' EndIf EndIf If ($options & 4) $sublist=dirlist($dirname+'\'+$filename+'\'+$mask,4) If Ubound($sublist)+1 ReDim preserve $list[Ubound($list)+Ubound($sublist)+1] For $subcounter=0 to Ubound($sublist) $counter=$counter+1 If $options & 2 $list[$counter]=$dirname+'\'+$filename+'\'+$sublist[$subcounter] Else $list[$counter]=$filename+'\'+$sublist[$subcounter] EndIf Next EndIf EndIf Case ($options & 2) $counter=$counter+1 $list[$counter]=$dirname+'\'+$filename Case 1 $counter=$counter+1 $list[$counter]=$filename EndSelect If $counter mod 10 ReDim preserve $list[$counter+10] EndIf EndIf $filename = Dir('') Loop
If $counter+1 ReDim preserve $list[$counter] Else $list='' EndIf
If $mask<>'*.*' AND ($options & 4) $filename=Dir($dirname+'\*.*') While $filename<>'' AND @ERROR=0 If $filename<>'.' AND $filename<>'..' If (GetFileAttr($dirname+'\'+$filename) & 16) $sublist=dirlist($dirname+'\'+$filename+'\'+$mask,4) If Ubound($sublist)+1 ReDim preserve $list[Ubound($list)+Ubound($sublist)+1] For $subcounter=0 to Ubound($sublist) $counter=$counter+1 If $options & 2 $list[$counter]=$dirname+'\'+$filename+'\'+$sublist[$subcounter] Else $list[$counter]=$filename+'\'+$sublist[$subcounter] EndIf Next EndIf EndIf EndIf $filename = Dir('') Loop EndIf
If $counter+1 ReDim preserve $list[$counter] Else $list='' EndIf
$dirlist=$list EndFunction
$dirarr=DIRLIST("c:\progfil\tiv",1)
$cantelem=Ubound($dirarr) ?$cantelem
this work fine, but count the files, I need that count only mus, mas med dirs and retorn a value 3.
tks for u help.
_________________________
Look always 4 the best...
|
|
Top
|
|
|
|
#108660 - 2003-11-21 09:37 PM
Re: Count subdirectorys not include files
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
Code:
for each $folder in FolderList('%ProgramFiles%') ? $folder next
Function FolderList($folderName,optional $mask) dim $objDir, $objFile, $t, $name $objDir = CreateObject('Scripting.FileSystemObject').GetFolder($folderName).SubFolders if @error exit 1 endif ; usually folder not found For Each $objFile In $objDir $name=$objFile.name if ($mask and instr($name,$mask)) or not $mask $t=$t+'|'+$name endif Next $FolderList=split(substr($t,2),'|') $objDir = 0 EndFunction
|
|
Top
|
|
|
|
#108661 - 2003-11-21 09:48 PM
Re: Count subdirectorys not include files
|
@lejo @rias
Starting to like KiXtart
Registered: 2003-09-02
Posts: 100
Loc: Medellin, Colombia
|
Lonkero, how I count these number of folders that show your script?
_________________________
Look always 4 the best...
|
|
Top
|
|
|
|
#108662 - 2003-11-21 09:52 PM
Re: Count subdirectorys not include files
|
@lejo @rias
Starting to like KiXtart
Registered: 2003-09-02
Posts: 100
Loc: Medellin, Colombia
|
$c=0 For Each $folder In FolderList('%ProgramFiles%') ? $folder $c=$c+1 TKS ALL 4 UR HLP
_________________________
Look always 4 the best...
|
|
Top
|
|
|
|
#108663 - 2003-11-21 09:53 PM
Re: Count subdirectorys not include files
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
hmmm, I would have went with:
$count = UBound(FolderList('%ProgramFiles%'))
myself 
-Shawn
|
|
Top
|
|
|
|
#108664 - 2003-11-21 09:53 PM
Re: Count subdirectorys not include files
|
ShaneEP
MM club member
   
Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
|
Dont forget the 'Next' at the end of that...
Code:
$c=0 For Each $folder In FolderList('%ProgramFiles%') ? $folder $c=$c+1 Next
|
|
Top
|
|
|
|
#108665 - 2003-11-21 10:01 PM
Re: Count subdirectorys not include files
|
Les
KiX Master
   
Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
|
|
|
Top
|
|
|
|
#108669 - 2003-11-21 10:25 PM
Re: Count subdirectorys not include files
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Here's my entry: Code:
break ON $ShellCMD = '%comspec% /c dir c:\data\scripts\ /b /a:d /s' ? "Running: $ShellCMD" $dirs = WSHPIPE($ShellCMD, 1) ? "directory count = " + ubound($dirs) Function WshPipe($ShellCMD, OPTIONAL $NoEcho) Dim $oExec, $Output $oExec = CreateObject("WScript.Shell").Exec($ShellCMD) If Not VarType($oExec)=9 $WshPipe="WScript.Shell Exec Unsupported" Exit 10 EndIf ;While Not $oExec.Status Loop $Output = $oExec.StdOut.ReadAll + $oExec.StdErr.ReadAll If Not $NoEcho ? $Output Endif $WshPipe=Split($Output,CHR(10)) Exit($oExec.ExitCode) EndFunction
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 1114 anonymous users online.
|
|
|