Well, maybe I could do this, in my own test-machine. But I don't like to do that on customers' PCs!
FUNCTION hb_DirScanM( cPath, aFileMask, cAttr, lrecursiv )
RETURN hb_DoScanM( hb_DirSepAdd( hb_defaultValue( cPath, "" ) ), ;
IIF( HB_ISARRAY( aFileMask ), aFileMask, IIF( HB_ISSTRING( aFileMask ), { aFileMask }, { hb_osFileMask() } ) ), ;
hb_defaultValue( cAttr, "" ), ;
hb_ps(), lrecursiv )
FUNCTION hb_doScanM( cPath, aMask, cAttr, cPathSep, lrecursiv )
LOCAL aFile
LOCAL lMatch
LOCAL aResult := {}
DEFAULT lrecursiv TO .T.
FOR EACH aFile IN hb_vfDirectory( cPath + hb_osFileMask(), cAttr + IF( lrecursiv, "D", "" ) )
lMatch := .F.
AEVAL( aMask, { | x | IIF( HB_ISSTRING( x ), lMatch := hb_FileMatch( aFile[ F_NAME ], x ) .OR. lMatch, Nil ) } )
IF "D" $ aFile[ F_ATTR ]
IF lMatch .AND. "D" $ cAttr
IF lrecursiv = .T.
AADD( aResult, aFile )
ENDIF
ENDIF
IF !( aFile[ F_NAME ] == "." .OR. aFile[ F_NAME ] == ".." .OR. aFile[ F_NAME ] == "" )
AEVAL( hb_DoScanM( cPath + aFile[ F_NAME ] + cPathSep, aMask, cAttr, cPathSep ), ;
{ | x | x[ F_NAME ] := aFile[ F_NAME ] + cPathSep + x[ F_NAME ], ;
AADD( aResult, x ) } )
ENDIF
ELSEIF lMatch
AADD( aResult, aFile )
ENDIF
NEXT
RETURN aResult
hb_DirScan(“cPath”, “*.txt”, [<cAttr>]) ➜ aFiles
found_array = hb_DirScan(…)
similar to hb_Directory() (refer to it for more..) with the
difference that it scans not only <cPath>
but also all subdirectories below <cPath>
(recursively).
hb_DirScan(“cPath”, “*.txt”, [<cAttr>]) ➜ aFiles
found_array = hb_DirScan(…)
similar to hb_Directory() (refer to it for more..) with the difference that it scans not only <cPath> but also all subdirectories below <cPath> (recursively).
Here is a recursive function that scans all the subdirectories. It can perform an action on every element found.
// dirscan - scans recursively directories and performs
<cAction> on every element
function DirScan(cFileMask,cPath,cUfunc,xValue,nDepth,nMaxdepth)
local aDirContent,count:=0,zz
#IFDEF __XHARBOUR__
local pFunc:=hb_funcPtr(cUfunc)
#ELSE
local pFunc:=__dynsN2Sym("cUfunc")
#ENDIF
if empty(pFunc)
outStd (cUfunc+": not found")
return nil
endif
DEFAULT nDepth to 1
if right(cpath,1)!=hb_osPathSeparator()
cpath+=hb_osPathSeparator()
endif
aDirContent=GetDirContent(cPath,cFileMask)
if len (aDirContent)>0
for zz:=1 to len (aDirContent)
if (nDepth<nMaxdepth.or.nMaxdepth=0)
if "D" $ aDirContent[zz,5]
dirScan(cFileMask,cPath+aDirContent[zz,1],cUfunc,xValue,++nDepth,nMaxDepth)
--nDepth
endif
endif
#IFDEF __XHARBOUR__
hb_exec(pFunc,nil,aDirContent[zz],xValue,cPath,cFileMask)
#ELSE
hb_execFromArray({pfunc,aDirContent[zz],xValue,cPath,cFileMask})
#ENDIF
next zz
else
if nDepth>0
#IFDEF __XHARBOUR__
hb_exec(pFunc,nil,{cPath,,,,"D"},xValue,"",cFileMask)
#ELSE
hb_execFromArray({pfunc,,{cPath,,,,"D"},xValue,"",cFileMask})
#ENDIF
endif
endif
return nil
function calcsize(aFileArr,dDate,cUpdir,cWc)
if .not. "D" $ aFilearr[5]
nTot+=aFileArr[2]
endif
return nil
(You need a "static nTot" in the main prg)
HTH,
Dan
--
--
You received this message because you are subscribed to the Google
Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: http://groups.google.com/group/harbour-users
---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/harbour-users/c248bdc6-4d80-4f22-a2a6-25796254f527o%40googlegroups.com.
And this is the missing getdircontent()... oops...
// content of a directory, sorted, dir first, then files,
subarrays {filename, filesize...}
// getDirContent(Path-terminating-with separator, wildcard
mask)-> aDir
func getDirContent(tpp,tpf)
LOCAL nStartAt := 1
TPL:=TPP+TPF
aDir := DIRECTORY(TPL, "HSD")
if TPF != "*.*" .and. .not. (tpf == "*")
aXdir :=DIRECTORY(tpP+"*.*", "HSD")
Aeval( aXdir,{|x,y|if("D" $ x.fileattrib,aadd(adir,x),nil)} )
endif
i := 1
WHILE i <= LEN(aDir)
IF ("D" $ aDir[i].fileattrib)
IF (aDir[i].filename == ".")
// NO . and ..
ADEL(aDir, i)
aDir := ASIZE(aDir, LEN(aDir) - 1)
LOOP
ELSEIF (aDir[i].filename == "..")
ADEL(aDir, i)
aDir := ASIZE(aDir, LEN(aDir) - 1)
LOOP
ENDIF
ENDIF
i++
END
// all sub-directories at the beginning of the list
ASORT(aDir,,, {|x,y| "D" $ x.fileattrib})
// other files
AEVAL(aDir, {|x,i| nStartAt := ;
IF("D" $ x.fileattrib, i, nStartAt)})
// Sort sub-directories only
ASORT(aDir,1, nStartAt, {|x,y| x.filename < y.filename})
nStartAt++
ASORT(aDir, nStartAt,, {|x,y| x.filename < y.filename})
return aDir
Dan
To view this discussion on the web visit https://groups.google.com/d/msgid/harbour-users/5f762595-bd0d-f32c-bb35-27c4e41ae1e1%40appliserver.com.