Page 1 of 1

How to get the folder size using MFT?

Posted: Sat Aug 21, 2021 11:06 am
by AZJIO
Is it possible to make PureBasic code from this example?
Another example on AutoIt3

Re: How to get the folder size using MFT?

Posted: Sat Aug 21, 2021 1:49 pm
by Mijikai
Yes, looks like straight WinApi to me.

A lazy way:

Code: Select all

EnableExplicit

;NOTE: RUN AS ADMIN!

Enumeration NTFS_INFO
  #NTFS_INFO_SECTOR = 4
  #NTFS_INFO_CLUSTER
  #NTFS_INFO_FREE_CLUSTER
EndEnumeration

Procedure.i FolderSize(Input.s,Index.i)
  Protected task.i
  Protected output.s
  Protected start.i
  Protected stop.i
  task = RunProgram("fsutil.exe","fsinfo ntfsinfo " + Input,#Null$,#PB_Program_Open|#PB_Program_Read)
  If task
    While ProgramRunning(task)
      If AvailableProgramOutput(task)
        output + ReadProgramString(task) + #CR$
      EndIf
    Wend 
    CloseProgram(task) 
  EndIf
  If output
    output = ReplaceString(StringField(output,Index,#CR$)," ","")
    start = FindString(output,":")
    If start
      start + 1
      stop = FindString(output,"(",start)
      output = ReplaceString(Mid(output,start,stop - start),".","")
      ProcedureReturn Val(output)
    EndIf
  EndIf
  ProcedureReturn #Null
EndProcedure

Debug "FolderSize: " + Str(FolderSize("c:",#NTFS_INFO_SECTOR)) + " bytes! - #NTFS_INFO_SECTOR"
Debug "FolderSize: " + Str(FolderSize("c:",#NTFS_INFO_CLUSTER)) + " bytes! - #NTFS_INFO_CLUSTER"
Debug "FolderSize: " + Str(FolderSize("c:",#NTFS_INFO_FREE_CLUSTER)) + " bytes! - #NTFS_INFO_FREE_CLUSTER"

End