Page 1 of 1

Simple question (from a simple person)

Posted: Sun Oct 21, 2012 6:45 am
by BruceN
I need to get the size of all files of a type (say, *.dbf) in a folder.

I can easily write a function that goes thru the file list, but it seems to me there would be an existing function that does it... but i can't find it.

thanks

Re: Simple question (from a simple person)

Posted: Sun Oct 21, 2012 7:14 am
by RDalzell
Bruce,

From the Alaska docs for function directory()

Code: Select all

#include "Directry.ch" 
 
PROCEDURE Main 
  LOCAL aDbfFiles := Directory("*.DBF") 
  LOCAL nCount    := Len(aDbfFiles) 
  LOCAL n, nSum 
 
  nSum := 0 
 
  FOR n:= 1 TO nCount 
    nSum += aDbfFiles[ n, F_SIZE ] 
  NEXT 
 
  ? nCount, "DBF files occupying", nSum, "Bytes" 

RETURN 

Re: Simple question (from a simple person)

Posted: Sun Oct 21, 2012 7:25 am
by BruceN
thanks...

i could have done something similar (although not quite as slick). I was hoping there as a function (perhaps something like DirSize(*.dbf) ) that would do it automatically, but I guess not.

Re: Simple question (from a simple person)

Posted: Sun Oct 21, 2012 7:37 am
by bwolfsohn
bruce,

simply change the first 2 lines of the code to:

function dirsize(aMask)
LOCAL aDbfFiles := Directory(aMask)

and the lst 2 to:

// ? nCount, "DBF files occupying", nSum, "Bytes"

RETURN(nSum)

and you have it..

dirsize("*.dbf")

Re: Simple question (from a simple person)

Posted: Sun Oct 21, 2012 7:58 am
by BruceN
That's basically what I did. The aFiles[ n, F_SIZE ] didn't work, so I changed things to:

FUNCTION FileTypeSize(Ftype)
LOCAL aFiles := Directory(Ftype)
LOCAL nCount := Len(aFiles)
LOCAL n, nSum:=0

FOR n:= 1 TO nCount
nSum += aFiles[ n, 2]
NEXT

RETURN nSum