SET TALK OFF
CLOSE DATA ALL
CREATE CURSOR DirSpace (DirPath C(254), FilesSize N(15,0), FilesBelow N(15,0), FileCount N(15,0), LDirPath N(15,0), Done L)
PRIVATE lcStartDir, lcOrigDir
lcStartDir = GETDIR() && This is causing a problem by returning the results in all uppercase.
lcOrigDir = SYS(5) + CURDIR()
=GetDirSpace(lcStartDir)
CD '&lcOrigDir'
WAIT CLEAR
INDEX ON LDirPath TAG LDirPath DESC
SET ORDER TO LDirPath
?? CHR(7)
SELECT DirPath, FilesSize FROM DirSpace INTO CURSOR tDirSpace ;
WHERE .T. ;
ORDER BY DirPath
SELECT DirSpace
SCAN
lcDirPath = ALLTRIM( DirSpace.DirPath )
WAIT WINDOW "Summing file space for: " + CHR(13) + lcDirPath NOWAIT
SELECT tDirSpace
SUM FilesSize TO lnFilesSize FOR lcDirPath $ tDirSpace.DirPath
SELECT DirSpace
REPLACE DirSpace.FilesBelow WITH lnFilesSize, ;
DirSpace.Done WITH .T.
ENDSCAN
WAIT CLEAR
INDEX ON FilesBelow TAG FilesBelow DESC
SET ORDER TO FilesBelow
BROWSE LAST FIELDS DirPath, FilesSize, FilesBelow, FileCount
?? CHR(7)
********************
FUNCTION GetDirSpace
PARAMETER pcDirectory
PRIVATE laDirArray, lnX, lnFileSizes, lnFileCount, lcDirectory
LOCAL llRetVal
llRetVal = .F.
DIMENSION laDirArray[1,1]
lcDirectory = '"' + pcDirectory + '"'
* ? TIME(), lcDirectory, LEN(lcDirectory)
TRY
CD (lcDirectory)
INSERT INTO DirSpace (DirPath, LDirPath) VALUES (pcDirectory, LEN(ALLTRIM(pcDirectory)) )
lnElements = ADIR(laDirArray, "*.*", "AHRS")
IF lnElements > 0
=ASORT(laDirArray, 2)
WAIT WINDOW "Processing directory: " + pcDirectory NOWAIT
ENDIF
*** Get File Sizes ***
lnFileSizes = 0
lnFileCount = 0
FOR lnX = 1 TO lnElements
IF NOT "D" $ laDirArray[lnX, 5]
lnFileSizes = lnFileSizes + laDirArray[lnX, 2]
lnFileCount = lnFileCount + 1
ENDIF
ENDFOR
REPLACE DirSpace.FilesSize WITH lnFileSizes, ;
DirSpace.FileCount WITH lnFileCount
*** DEBUGOUT lnFileSizes
*** Recursive Call With Directories ***
lnElements = ADIR(laDirArray, "*.*", "D")
FOR lnX = 1 TO lnElements
IF "D" $ laDirArray[lnX, 5]
lcSubDirectory = laDirArray[lnX, 1]
IF lcSubDirectory # "." AND lcSubDirectory # ".."
=GetDirSpace(pcDirectory + lcSubDirectory + "\")
ENDIF
ENDIF
ENDFOR
llRetVal = .T.
CATCH
? TIME(), [>>>Problem changing to directory], lcDirectory
ENDTRY
RETURN llRetVal
No comments:
Post a Comment