[futurebasic] Re: [FB] folder size

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : June 2000 : Group Archive : Group : All Groups

From: Pontus <warlordpontus@...>
Date: Fri, 9 Jun 2000 16:50:28 +0200
>I am using the following to get the total size of files within a folder.
>It occurred to me that there might be a simple toolbox call

Might be. You'll have to ask someone a bit more experienced.

>or something that performs the same task in a faster way...

Your original function should be fast enough, but this one doesn't use
pathnames. I just whipped this up, but I think it should be bugfree.

-----
CLEAR LOCAL MODE
LOCAL FN MyGetFolderSize& (WdRefNum%)
  DIM Pb.200, NumFiles%, FileIdx%, TotalSize&, Err%

  'FB defines _ioFlFndrInfo as 8, but most of the time it's 32!
  _myIoFlFndrInfo = 32

  Pb.ioFDirIndex% = -1
  Pb.ioVRefNum% = WdRefNum%
  Err% = FN GETCATINFO (@Pb)
  LONG IF Err% = _noErr
    NumFiles% = Pb.ioDrNmFls%
    LONG IF NumFiles% > 0
      FOR FileIdx% = 1 TO NumFiles%
        Pb.ioDrDirID& = _nil
        Pb.ioFDirIndex% = FileIdx%
        Err% = FN GETCATINFO (@Pb)

        LONG IF Err% = _noErr
          LONG IF PEEK (@Pb + _ioFlAttrib) AND BIT(4)
            'This is a folder...
            'And you're in trouble, though I think this function can
            'call itself under FB^3, so you'd write something like:
            'TotalSIze& = TotalSize& + FN MyGetFolderSize&
          XELSE
            'This is a file...

            'Remove the LONG IF if you want the function to count
            'invisible files
            LONG IF (Pb.myIoFlFndrInfo.Fdflags% AND _fInvisible) = _false
              TotalSize& = TotalSize& + Pb.ioFlLgLen& + Pb.ioFlRLgLen&
            END IF
          END IF
        XELSE
          FileIdx% = NumFiles%+1                    'Abort!
          Err% = -1
        END IF
      NEXT
    END IF
  END IF

  IF Err% <> _noErr THEN TotalSize& = -1
END FN = TotalSize&                  'Returns size in bytes

Pontus Ilbring

"Black holes are where god divided by zero."