#151012 - 2005-11-04 02:36 PM
3 Level ONLY recurse Dir - URGENT
|
MACE
Starting to like KiXtart
Registered: 2004-09-07
Posts: 150
Loc: Manchester UK
|
Can anyone spot why I only get one $Project Folder List for each $Source rather than a list of $Client with all $Location with all $Project tree ! Code:
dim $CLIENT[999] dim $LOCATION[200] dim $PROJECT[200] dim $SOURCE[4] break on
$SOURCE[1] = READPROFILESTRING(@SCRIPTDIR + "\MENU.INI","DRIVES","SOURCE") $SOURCE[2] = READPROFILESTRING(@SCRIPTDIR + "\MENU.INI","DRIVES","DEST") $SOURCE[3] = READPROFILESTRING(@SCRIPTDIR + "\MENU.INI","DRIVES","ARC1") $SOURCE[4] = READPROFILESTRING(@SCRIPTDIR + "\MENU.INI","DRIVES","ARC2") if Open(2, "c:\dirlist.txt",5) = 0 for $s= 1 to 4 $CLIENT=Dir($SOURCE[$s]) ? $CLIENT While Not @ERROR If (16 & GetFileAttr($SOURCE[$s]+"\"+$CLIENT)) if not $CLIENT = "." and not $CLIENT = ".." and not $CLIENT = ""
$LOCATION=Dir($SOURCE[$s]+"\"+$CLIENT) While Not @ERROR If (16 & GetFileAttr($SOURCE[$s]+"\"+$CLIENT+"\"+$LOCATION)) if not $LOCATION = "." and not $LOCATION = ".." and not $LOCATION = ""
$PROJECT=Dir($SOURCE[$s]+"\"+$CLIENT+"\"+$LOCATION) While Not @ERROR If (16 & GetFileAttr($SOURCE[$s]+"\"+$CLIENT+"\"+$LOCATION+"\"+$PROJECT)) if not $PROJECT = "." and not $PROJECT = ".." and not $PROJECT = "" $LINE=$source[$s]+","+$client+","+$location+","+$project+@CRLF ? ""+$LINE ;$x = WRITELINE (2,$LINE) endif endif $PROJECT=Dir() ; retrieve next Project Loop endif endif $LOCATION=Dir() ; retrieve next Location Loop if EndIf $CLIENT = Dir() ; retrieve next Client Loop next close(2)
|
|
Top
|
|
|
|
#151017 - 2005-11-04 03:18 PM
Re: 3 Level ONLY recurse Dir - URGENT
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
If the UDF doesn't do what you want and you need to re-engineer, here's a simple example to get you started: Code:
Break ON $=SetOption("Explicit","ON") $=SetOption("WrapAtEOL","ON") $=funRecurse("C:\",3) Function funRecurse($sDir,$iLevel) Dim $sEntry $iLevel=$iLevel-1 $sEntry=Dir($sDir) While Not @ERROR If NOT($sEntry="" OR $sEntry="." OR $sEntry="..") $sEntry=$sDir+"\"+$sEntry ""+$iLevel+": "+$sEntry+@CRLF If (GetFileAttr($sEntry) & 16) AND $iLevel funRecurse($sEntry,$iLevel) EndIf EndIf $sEntry=Dir() Loop EndFunction
|
|
Top
|
|
|
|
#151018 - 2005-11-04 04:09 PM
Re: 3 Level ONLY recurse Dir - URGENT
|
MACE
Starting to like KiXtart
Registered: 2004-09-07
Posts: 150
Loc: Manchester UK
|
DirPlus does NOT allow me to easily do only 3 levels as required. The following I believe should work but for an error insisting there is a missing comma in the Dir(#) ? Suggestions Code:
break on global $CLIENT global $LOCATION global $PROJECT dim $SOURCE[4] ;dim $CLIENT[9999] ;dim $LOCATION[200] ;dim $PROJECT[200] debug on $SOURCE[1] = READPROFILESTRING(@SCRIPTDIR + "\MENU.INI","DRIVES","SOURCE") $SOURCE[2] = READPROFILESTRING(@SCRIPTDIR + "\MENU.INI","DRIVES","DEST") $SOURCE[3] = READPROFILESTRING(@SCRIPTDIR + "\MENU.INI","DRIVES","ARC1") $SOURCE[4] = READPROFILESTRING(@SCRIPTDIR + "\MENU.INI","DRIVES","ARC2") if Open(2, "c:\dirlist.txt",5) = 0 for $s= 1 to 4 ? "#"+$SOURCE[$s] ClntDir($s) next ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Function ClntDir($S) $CLIENT=Dir(""+$SOURCE[$s],0) $CC=0 While Not @ERROR If (16 & GetFileAttr($SOURCE[$s]+"\"+$CLIENT)) if not $CLIENT = "." and not $CLIENT = ".." and not $CLIENT = "" $CC=$CC+1 $CLIENT[$CC] = $CLIENT LocnDir($S,$CC) endif EndIf $CLIENT = Dir() ; retrieve next Client Loop EndFunction ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Function LocnDir($S,$CC) $LOCATION=Dir(""+$SOURCE[$s]+"\"+$CLIENT[$CC],0) $LC=0 While Not @ERROR If (16 & GetFileAttr($SOURCE[$s]+"\"+$CLIENT[$CC]+"\"+$LOCATION)) if not $LOCATION = "." and not $LOCATION = ".." and not $LOCATION = "" $LC=$LC+1 $LOCATION[$LC] = $LOCATION ProjDir($S,$CC,$LC) endif endif $LOCATION=Dir() ; retrieve next Location Loop EndFunction ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Function ProjDir($S,$CC,$LC) $PROJECT=Dir(""+$SOURCE[$s]+"\"+$CLIENT[$CC]+"\"+$LOCATION[$LC],0) $PC=0 While Not @ERROR If (16 & GetFileAttr($SOURCE[$s]+"\"+$CLIENT[$CC]+"\"+$LOCATION[$LC]+"\"+$PROJECT)) if not $PROJECT = "." and not $PROJECT = ".." and not $PROJECT = "" $PC=$PC+1 $PROJECT[$PC] = $PROJECT $LINE=$source[$s]+","+$client[$CC]+","+$location[$LC]+","+$project[$PC]+@CRLF ? ""+$LINE $x = WRITELINE (2,$LINE) endif endif $PROJECT=Dir() ; retrieve next Project Loop EndFunction
|
|
Top
|
|
|
|
#151022 - 2005-11-04 05:01 PM
Re: 3 Level ONLY recurse Dir - URGENT
|
MACE
Starting to like KiXtart
Registered: 2004-09-07
Posts: 150
Loc: Manchester UK
|
I tried this but it can not handle nesting and /s3 as above did not seem to work - only 1 level displayed.
Code:
break on global $SOURCE dim $SOURCE[4] ;debug on $SOURCE[1] = READPROFILESTRING(@SCRIPTDIR + "\MENU.INI","DRIVES","SOURCE") $SOURCE[2] = READPROFILESTRING(@SCRIPTDIR + "\MENU.INI","DRIVES","DEST") $SOURCE[3] = READPROFILESTRING(@SCRIPTDIR + "\MENU.INI","DRIVES","ARC1") $SOURCE[4] = READPROFILESTRING(@SCRIPTDIR + "\MENU.INI","DRIVES","ARC2") if Open(2, "c:\dirlist.txt",5) = 0 for $s= 1 to 4 $dir1 = dirplus($SOURCE[$s],"/ad") ; ? dir1 for each $Client in $dir1 $dir2 = dirplus($SOURCE[$s]+"\"+$dir1,"/ad") ; ? dir2 for each $Location in $dir2 $dir3 = dirplus($SOURCE[$s]+"\"+$dir1+"\"+$dir2,"/ad") ; ? dir3 for each $Project in $dir3 $Line=$SOURCE[$s]+"\"+$dir1+"\"+$dir2+"\"+$dir3 ? $LINE ; $x = WRITELINE (2,$LINE) ; List of Folders at 3 levels deep next next next next endif close (2) ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;Function DIRPlus()
|
|
Top
|
|
|
|
#151023 - 2005-11-04 05:10 PM
Re: 3 Level ONLY recurse Dir - URGENT
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
With a minor modification the simple example that I gave you will do what I think you want, which is not to iterate a DIR() to three levels, but to get the directories at the third level: Code:
Break ON $=SetOption("Explicit","ON") $=SetOption("WrapAtEOL","ON") $=funRecurse("C:\",3) Function funRecurse($sDir,$iLevel) Dim $sEntry $iLevel=$iLevel-1 $sEntry=Dir($sDir) While Not @ERROR If NOT($sEntry="" OR $sEntry="." OR $sEntry="..") $sEntry=Join(Split($sDir+"\"+$sEntry,"\\"),"\") If (GetFileAttr($sEntry) & 16) If $iLevel funRecurse($sEntry,$iLevel) Else $sEntry+@CRLF EndIf EndIf EndIf $sEntry=Dir() Loop EndFunction
|
|
Top
|
|
|
|
#151024 - 2005-11-04 05:11 PM
Re: 3 Level ONLY recurse Dir - URGENT
|
Bryce
KiX Supporter
   
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
if you are only after files...
Code:
$dir = dirplus($source,'/s3 /a-d') for each $file in $dir ? $file.name next
That will only return the files in all sub folders that are 3 deep from the root of $source. Don't forget, that DirPlus() returns an array of FSO object's not strings, hence the $file.name.
|
|
Top
|
|
|
|
#151025 - 2005-11-04 05:18 PM
Re: 3 Level ONLY recurse Dir - URGENT
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Quote:
if you are only after files...
Other way round - he's after directories, not files.
|
|
Top
|
|
|
|
#151027 - 2005-11-04 05:58 PM
Re: 3 Level ONLY recurse Dir - URGENT
|
Bryce
KiX Supporter
   
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
i had to go stomp some fires....
but here... Code:
$source = "v:\"
$folders = dirplus($source,"/ad /s3") for each $f in $folders if ubound(split(split($f.path,$source)[1],'\')) = 2 ? $f.path endif next
|
|
Top
|
|
|
|
#151029 - 2005-11-04 06:19 PM
Re: 3 Level ONLY recurse Dir - URGENT
|
Bryce
KiX Supporter
   
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
Code:
$source = "v:\"
$folders = dirplus($source,"/ad /s3") for each $f in $folders select case ubound(split(split($f.path,$source)[1],'\')) = 0 ? "level - 1 " + $f.path case ubound(split(split($f.path,$source)[1],'\')) = 1 ? "level - 2 " + $f.path case ubound(split(split($f.path,$source)[1],'\')) = 2 ? "level - 3 " + $f.path endselect next
|
|
Top
|
|
|
|
#151031 - 2005-11-04 06:34 PM
Re: 3 Level ONLY recurse Dir - URGENT
|
Bryce
KiX Supporter
   
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
opps... had bugs  Code:
$source = "c:\program files"
$folders = dirplus($source,"/ad /s2") for each $f in $folders select case ubound(split(split($f.path,$source)[1],'\')) = 1 ? "level - 1 " + $f.path case ubound(split(split($f.path,$source)[1],'\')) = 2 ? "level - 2 " + $f.path case ubound(split(split($f.path,$source)[1],'\')) = 3 ? "level - 3 " + $f.path endselect next
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 1198 anonymous users online.
|
|
|