Code:
#COMPILE EXE '#Win 8.04# #DIM ALL #REGISTER NONE #INCLUDE "Win32Api.inc" '#2005-01-27# '______________________________________________________________________________ FUNCTION FolderByteCount(Folder AS STRING, Mask AS STRING) AS QUAD LOCAL hFind AS DWORD LOCAL FileData AS WIN32_FIND_DATA LOCAL qTotal AS QUAD LOCAL qLowHigh AS QUAD LOCAL pHigh AS DWORD POINTER pHigh = VARPTR(qLowHigh) + 4 'Point to the high part of the quad, low part is always zero. IF ASC(Folder, - 1) <> 92 THEN Folder = Folder & "\" 'Must end with a backlash, ASC is faster than RIGHT$ hFind = FindFirstFile(Folder & Mask, FileData) IF hFind <> %INVALID_HANDLE_VALUE THEN DO qTotal = qTotal + FileData.nFileSizeLow 'nFileSizeHigh is rarely bigger than zero, 'you need a file bigger than 4 gigabytes for that. 'So, to increase speed a little, 'let's do following calculation only when needed. IF FileData.nFileSizeHigh THEN 'Does the file is bigger than 4 gigabytes ? @pHigh = FileData.nFileSizeHigh 'Fill the high part of a quad using pointer. qTotal = qTotal + qLowHigh 'Add the filled quad to Total END IF LOOP WHILE FindNextFile(hFind, FileData) FindClose hFind END IF FUNCTION = qTotal END FUNCTION '______________________________________________________________________________ FUNCTION PBMAIN () AS LONG LOCAL Path AS STRING LOCAL Mask AS STRING Path = "C:\Windows\System32\" Mask = "*" MessageBox %HWND_DESKTOP, FORMAT$(FolderByteCount(Path, Mask), "###,###") & _ " bytes in " & Path & Mask, _ "FolderByteCount", %MB_ICONINFORMATION OR %MB_OK END FUNCTION '______________________________________________________________________________
Leave a comment: