Announcement

Collapse
No announcement yet.

Is there a fast(er)way of....

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Is there a fast(er)way of....

    ....getting the total size, in bytes, of all specified files in a sub-directory?

    For example, I want to get the total byte count for "c:\windows\*.dll". Currently, I have to open each file in BINARY mode, get the file size then close it. Not really a good way of going.

    I hope I'm making sense.
    There are no atheists in a fox hole or the morning of a math test.
    If my flag offends you, I'll help you pack.

  • #2
    If you use the FindFirstFile/FindNextFile/FindClose API's, the structure used by them includes members that contain the files' sizes. You do not have to open the files to use those API's.

    Comment


    • #3
      This should work (a sample of what Clay suggested - PBWIN 8+):

      (excludes hidden files - pagefile.sys is apparently a monster)

      Code:
      #COMPILE EXE
      #DIM ALL
      
      #INCLUDE "WIN32API.INC"
      
      DECLARE FUNCTION FolderByteCount(inFolder AS STRING) AS QUAD
      
      FUNCTION PBMAIN () AS LONG
      
          ? FORMAT$(FolderByteCount("C:\"))
      
      END FUNCTION
      
      FUNCTION FolderByteCount(inFolder AS STRING) AS QUAD
      
          LOCAL SH    AS DWORD
          LOCAL WFD   AS WIN32_FIND_DATA
          LOCAL fSpec AS ASCIIZ * %MAX_PATH
          LOCAL qRet  AS QUAD
          LOCAL qFS   AS QUAD
          
          fSpec = inFolder
          IF RIGHT$(fSpec, 1) <> "\" THEN
              fSpec = fSpec + "\"
          END IF
          
          fSpec = fSpec + "*.*"
          
          SH = FindFirstFile(fSpec, WFD)
          IF SH <> %INVALID_HANDLE_VALUE THEN
              DO
                  IF (WFD.dwFileAttributes AND %FILE_ATTRIBUTE_HIDDEN) <> %FILE_ATTRIBUTE_HIDDEN THEN
                      qFS = MAK(QUAD, WFD.nFileSizeLow, WFD.nFileSizeHigh)
                      qRet = qRet + qFS
                  END IF
              LOOP WHILE FindNextFile(SH, WFD)
              FindClose SH
          END IF
          
          FUNCTION = qRet
      
      END FUNCTION
      Adam Drake
      Drake Software

      Comment


      • #4
        Nice one Adam. :top:
        By chance do you know a link that goes a bit more detailed?

        I have barely touched FindFirstFile etc...but would like to do a lil like the properties window and dir each file, get properties and show it. like if I did it myself by right clicking and getting the properties

        I am sure its been done before but I hate re-inventing the wheel, if the wheel invented is already better than the one I am trying.
        Engineer's Motto: If it aint broke take it apart and fix it

        "If at 1st you don't succeed... call it version 1.0"

        "Half of Programming is coding"....."The other 90% is DEBUGGING"

        "Document my code????" .... "WHYYY??? do you think they call it CODE? "

        Comment


        • #5
          Here's a shot at a bit more detailed:

          Code:
          #PBFORMS CREATED V1.51
          '-----------------------------------------------------------------------------------------------------------------
          ' The first line in this file is a PB/Forms metastatement.
          ' It should ALWAYS be the first line of the file. Other
          ' PB/Forms metastatements are placed at the beginning and
          ' end of "Named Blocks" of code that should be edited
          ' with PBForms only. Do not manually edit or delete these
          ' metastatements or PB/Forms will not be able to reread
          ' the file correctly.  See the PB/Forms documentation for
          ' more information.
          ' Named blocks begin like this:    #PBFORMS BEGIN ...
          ' Named blocks end like this:      #PBFORMS END ...
          ' Other PB/Forms metastatements such as:
          '     #PBFORMS DECLARATIONS
          ' are used by PB/Forms to insert additional code.
          ' Feel free to make changes anywhere else in the file.
          '-----------------------------------------------------------------------------------------------------------------
          
          #COMPILE EXE
          #DIM ALL
          
          '-----------------------------------------------------------------------------------------------------------------
          '   ** Includes **
          '-----------------------------------------------------------------------------------------------------------------
          #PBFORMS BEGIN INCLUDES
          #IF NOT %DEF(%WINAPI)
              #INCLUDE "WIN32API.INC"
          #ENDIF
          #PBFORMS END INCLUDES
          '-----------------------------------------------------------------------------------------------------------------
          
          '-----------------------------------------------------------------------------------------------------------------
          '   ** Constants **
          '-----------------------------------------------------------------------------------------------------------------
          #PBFORMS BEGIN CONSTANTS
          %IDD_DIALOG_FOLDERLIST    =  101
          %IDC_LABEL_FOLDER         = 1002
          %IDC_TEXTBOX_FOLDER       = 1001
          %IDC_LABEL_FILESFOLDERS   = 1003
          %IDC_FRAME_PROPERTIES     = 1005
          %IDC_BUTTON_BROWSE        = 1006
          %IDC_BUTTON_GO            = 1007
          %IDC_LABEL_FILENAME1      = 1008
          %IDC_LABEL_FILENAME       = 1009
          %IDC_LABEL_FILEATTRIBUTES = 1010
          %IDC_LABEL_FILESIZE1      = 1012
          %IDC_LABEL_FILESIZE       = 1013
          %IDC_LABEL_CREATED1       = 1015
          %IDC_LABEL_MODIFIED1      = 1017
          %IDC_LABEL_ACCESSED1      = 1019
          %IDC_LABEL_CREATED        = 1014
          %IDC_LABEL_MODIFIED       = 1016
          %IDC_LABEL_ACCESSED       = 1018
          %IDC_LISTBOX_FILELIST     = 1004
          %IDC_LISTBOX_FILEATTR     = 1011
          %IDC_CHECKBOX_HIDDENFILES = 1020
          #PBFORMS END CONSTANTS
          '-----------------------------------------------------------------------------------------------------------------
          
          '-----------------------------------------------------------------------------------------------------------------
          '   ** Declarations **
          '-----------------------------------------------------------------------------------------------------------------
          DECLARE CALLBACK FUNCTION ShowDIALOG_FOLDERLISTProc()
          DECLARE FUNCTION ShowDIALOG_FOLDERLIST(BYVAL hParent AS DWORD) AS LONG
          #PBFORMS DECLARATIONS
          '-----------------------------------------------------------------------------------------------------------------
          
          DECLARE FUNCTION BrowseForFolder (hWnd AS DWORD, strTitle AS STRING, StartFolder AS STRING) AS STRING
          DECLARE FUNCTION CheckAttr(dwAttributes AS DWORD, lAttrib AS LONG) AS LONG
          DECLARE FUNCTION FormatDateTime(inDate AS FILETIME) AS STRING
          
          '-----------------------------------------------------------------------------------------------------------------
          '   ** Main Application Entry Point **
          '-----------------------------------------------------------------------------------------------------------------
          FUNCTION PBMAIN()
              ShowDIALOG_FOLDERLIST %HWND_DESKTOP
          END FUNCTION
          '-----------------------------------------------------------------------------------------------------------------
          
          '-----------------------------------------------------------------------------------------------------------------
          '   ** CallBacks **
          '-----------------------------------------------------------------------------------------------------------------
          CALLBACK FUNCTION ShowDIALOG_FOLDERLISTProc()
          
              LOCAL NewFolder     AS STRING
              LOCAL hWndLB        AS DWORD
              LOCAL LBSel         AS LONG
              LOCAL SH            AS DWORD
              LOCAL fSpec         AS ASCIIZ * %MAX_PATH
              LOCAL WFD           AS WIN32_FIND_DATA
              LOCAL x             AS LONG
              LOCAL tmp           AS STRING
              LOCAL dwAttrs       AS DWORD
              LOCAL qSize         AS QUAD
              LOCAL ih            AS LONG
          
              STATIC StartFolder  AS STRING
          
              DIM FileList()      AS STATIC WIN32_FIND_DATA
              DIM FileCount       AS LONG
          
              SELECT CASE AS LONG CBMSG
                  CASE %WM_INITDIALOG
                      ' Initialization handler
                      StartFolder = "C:\"
                      CONTROL SET TEXT CBHNDL, %IDC_TEXTBOX_FOLDER, StartFolder
                      PostMessage CBHNDL, %WM_COMMAND, MAK(LONG, %IDC_BUTTON_GO, %BN_CLICKED), 0
          
                  CASE %WM_NCACTIVATE
                      STATIC hWndSaveFocus AS DWORD
                      IF ISFALSE CBWPARAM THEN
                          ' Save control focus
                          hWndSaveFocus = GetFocus()
                      ELSEIF hWndSaveFocus THEN
                          ' Restore control focus
                          SetFocus(hWndSaveFocus)
                          hWndSaveFocus = 0
                      END IF
          
                  CASE %WM_COMMAND
                      ' Process control notifications
                      SELECT CASE AS LONG CBCTL
                          CASE %IDC_TEXTBOX_FOLDER
          
                          CASE %IDC_LABEL_FOLDER
          
                          CASE %IDC_LABEL_FILESFOLDERS
          
                          CASE %IDC_LISTBOX_FILELIST
                              IF CBCTLMSG = %LBN_SELCHANGE THEN
                                  hWndLB = GetDlgItem(CBHNDL, CBCTL)
                                  LBSel = SendMessage(hWndLB, %LB_GETCURSEL, 0, 0)
                                  IF LBSel <> %LB_ERR THEN
                                      INCR LBSel
                                      CONTROL SET TEXT CBHNDL, %IDC_LABEL_FILENAME, FileList(LBSel).cFileName
                                      LISTBOX RESET CBHNDL, %IDC_LISTBOX_FILEATTR
                                      dwAttrs = FileList(LBSel).dwFileAttributes
                                      IF CheckAttr(dwAttrs, %FILE_ATTRIBUTE_READONLY) THEN LISTBOX ADD CBHNDL, %IDC_LISTBOX_FILEATTR, "Read Only"
                                      IF CheckAttr(dwAttrs, %FILE_ATTRIBUTE_HIDDEN) THEN LISTBOX ADD CBHNDL, %IDC_LISTBOX_FILEATTR, "Hidden"
                                      IF CheckAttr(dwAttrs, %FILE_ATTRIBUTE_SYSTEM) THEN LISTBOX ADD CBHNDL, %IDC_LISTBOX_FILEATTR, "System"
                                      IF CheckAttr(dwAttrs, %FILE_ATTRIBUTE_DIRECTORY) THEN LISTBOX ADD CBHNDL, %IDC_LISTBOX_FILEATTR, "Directory"
                                      qSize = MAK(QUAD, FileList(LBSel).nFileSizeLow, FileList(LBSel).nFileSizeHigh)
                                      CONTROL SET TEXT CBHNDL, %IDC_LABEL_FILESIZE, FORMAT$(qSize, "###,###,###,###")
                                      CONTROL SET TEXT CBHNDL, %IDC_LABEL_CREATED, FormatDateTime(FileList(LBSel).ftCreationTime)
                                      CONTROL SET TEXT CBHNDL, %IDC_LABEL_MODIFIED, FormatDateTime(FileList(LBSel).ftLastWriteTime)
                                      CONTROL SET TEXT CBHNDL, %IDC_LABEL_ACCESSED, FormatDateTime(FileList(LBSel).ftLastAccessTime)
                                  END IF
                              END IF
          
                          CASE %IDC_FRAME_PROPERTIES
          
                          CASE %IDC_BUTTON_BROWSE
                              IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                                  NewFolder = BrowseForFolder(CBHNDL, "Choose Folder", StartFolder)
                                  IF NewFolder <> "" THEN
                                      CONTROL SET TEXT CBHNDL, %IDC_TEXTBOX_FOLDER, NewFolder
                                      StartFolder = NewFolder
                                  END IF
                              END IF
          
                          CASE %IDC_BUTTON_GO
                              IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                                  CONTROL GET CHECK CBHNDL, %IDC_CHECKBOX_HIDDENFILES TO ih
                                  RESET FileCount
                                  ERASE FileList()
                                  LISTBOX RESET CBHNDL, %IDC_LISTBOX_FILELIST
                                  CONTROL GET TEXT CBHNDL, %IDC_TEXTBOX_FOLDER TO NewFolder
                                  fSpec = NewFolder
                                  IF RIGHT$(fSpec, 1) <> "\" THEN
                                      fSpec = fSpec + "\"
                                  END IF
                                  fSpec = fSpec + "*.*"
                                  SH = FindFirstFile(fSpec, WFD)
                                  IF SH <> %INVALID_HANDLE_VALUE THEN
                                      DO
                                          IF LEFT$(WFD.cFileName, 1) <> "." THEN ' Exclude '.' and '..'
                                              IF ISFALSE(ih) THEN
                                                  IF ISFALSE(CheckAttr(WFD.dwFileAttributes, %FILE_ATTRIBUTE_HIDDEN)) THEN
                                                      INCR FileCount
                                                      REDIM PRESERVE FileList(1 TO FileCount) AS STATIC WIN32_FIND_DATA
                                                      TYPE SET FileList(FileCount) = WFD
                                                  END IF
                                              ELSE
                                                  INCR FileCount
                                                  REDIM PRESERVE FileList(1 TO FileCount) AS STATIC WIN32_FIND_DATA
                                                  TYPE SET FileList(FileCount) = WFD
                                              END IF
                                          END IF
                                      LOOP WHILE FindNextFile(SH, WFD)
                                      FindClose SH
                                  END IF
                                  IF FileCount = 0 THEN
                                      MSGBOX "No File(s)/Folder(s) found in: "+NewFolder, %MB_ICONERROR OR %MB_TASKMODAL, "File Property Test"
                                      EXIT FUNCTION
                                  END IF
                                  FOR x = 1 TO FileCount
                                      tmp = FileList(x).cFileName
                                      IF (FileList(x).dwFileAttributes AND %FILE_ATTRIBUTE_DIRECTORY) = %FILE_ATTRIBUTE_DIRECTORY THEN
                                          tmp = tmp + " (DIR)"
                                      END IF
                                      LISTBOX ADD CBHNDL, %IDC_LISTBOX_FILELIST, tmp
                                  NEXT
                              END IF
          
                          CASE %IDC_LABEL_FILENAME1
          
                          CASE %IDC_LABEL_FILEATTRIBUTES
          
                          CASE %IDC_LISTBOX_FILEATTR
          
                          CASE %IDC_LABEL_FILESIZE1
          
                          CASE %IDC_LABEL_CREATED
          
                          CASE %IDC_LABEL_CREATED1
          
                          CASE %IDC_LABEL_MODIFIED
          
                          CASE %IDC_LABEL_MODIFIED1
          
                          CASE %IDC_LABEL_ACCESSED
          
                          CASE %IDC_LABEL_ACCESSED1
          
                      END SELECT
              END SELECT
          END FUNCTION
          '-----------------------------------------------------------------------------------------------------------------
          
          '-----------------------------------------------------------------------------------------------------------------
          '   ** Dialogs **
          '-----------------------------------------------------------------------------------------------------------------
          FUNCTION ShowDIALOG_FOLDERLIST(BYVAL hParent AS DWORD) AS LONG
              LOCAL lRslt AS LONG
          
          #PBFORMS BEGIN DIALOG %IDD_DIALOG_FOLDERLIST->->
              LOCAL hDlg  AS DWORD
          
              DIALOG NEW hParent, "Folder Property List", 70, 70, 495, 318, %WS_POPUP OR %WS_BORDER OR %WS_DLGFRAME OR _
                  %WS_SYSMENU OR %WS_MINIMIZEBOX OR %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR _
                  %DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR _
                  %WS_EX_RIGHTSCROLLBAR, TO hDlg
              CONTROL ADD TEXTBOX,  hDlg, %IDC_TEXTBOX_FOLDER, "", 80, 5, 100, 13
              CONTROL ADD LABEL,    hDlg, %IDC_LABEL_FOLDER, "Folder:", 5, 7, 70, 10
              CONTROL ADD LABEL,    hDlg, %IDC_LABEL_FILESFOLDERS, "File(s)/Folder(s):", 5, 30, 100, 10
              CONTROL ADD LISTBOX,  hDlg, %IDC_LISTBOX_FILELIST, , 5, 40, 245, 275, %WS_CHILD OR %WS_VISIBLE OR _
                  %WS_TABSTOP OR %WS_VSCROLL OR %LBS_NOTIFY, %WS_EX_CLIENTEDGE OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR _
                  %WS_EX_RIGHTSCROLLBAR
              CONTROL ADD FRAME,    hDlg, %IDC_FRAME_PROPERTIES, "Properties", 255, 40, 235, 270
              CONTROL ADD BUTTON,   hDlg, %IDC_BUTTON_BROWSE, "&Browse", 185, 5, 50, 15
              CONTROL ADD BUTTON,   hDlg, %IDC_BUTTON_GO, "&Go", 185, 20, 50, 15
              CONTROL ADD LABEL,    hDlg, %IDC_LABEL_FILENAME1, "Filename:", 260, 55, 55, 10
              CONTROL ADD LABEL,    hDlg, %IDC_LABEL_FILENAME, "", 320, 55, 165, 10
              CONTROL ADD LABEL,    hDlg, %IDC_LABEL_FILEATTRIBUTES, "File Attributes:", 260, 65, 55, 10
              CONTROL ADD LISTBOX,  hDlg, %IDC_LISTBOX_FILEATTR, , 320, 65, 125, 80, %WS_CHILD OR %WS_VISIBLE OR _
                  %WS_TABSTOP OR %WS_VSCROLL OR %LBS_NOTIFY, %WS_EX_CLIENTEDGE OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR _
                  %WS_EX_RIGHTSCROLLBAR
              CONTROL ADD LABEL,    hDlg, %IDC_LABEL_FILESIZE1, "File Size:", 260, 150, 55, 10
              CONTROL ADD LABEL,    hDlg, %IDC_LABEL_FILESIZE, "", 320, 150, 165, 10
              CONTROL ADD LABEL,    hDlg, %IDC_LABEL_CREATED, "", 320, 170, 165, 10
              CONTROL ADD LABEL,    hDlg, %IDC_LABEL_CREATED1, "Created:", 260, 170, 55, 10
              CONTROL ADD LABEL,    hDlg, %IDC_LABEL_MODIFIED, "", 320, 180, 165, 10
              CONTROL ADD LABEL,    hDlg, %IDC_LABEL_MODIFIED1, "Modified:", 260, 180, 55, 10
              CONTROL ADD LABEL,    hDlg, %IDC_LABEL_ACCESSED, "", 320, 190, 165, 10
              CONTROL ADD LABEL,    hDlg, %IDC_LABEL_ACCESSED1, "Accessed:", 260, 190, 55, 10
              CONTROL ADD CHECKBOX, hDlg, %IDC_CHECKBOX_HIDDENFILES, "Include Hidden Files", 305, 15, 100, 10
          #PBFORMS END DIALOG
          
              DIALOG SHOW MODAL hDlg, CALL ShowDIALOG_FOLDERLISTProc TO lRslt
          
          #PBFORMS BEGIN CLEANUP %IDD_DIALOG_FOLDERLIST
          #PBFORMS END CLEANUP
          
              FUNCTION = lRslt
          END FUNCTION
          '-----------------------------------------------------------------------------------------------------------------
          ' Browse For Folder Code From:
          ' http://www.powerbasic.com/support/pbforums/showthread.php?t=35009&highlight=shbrowseforfolder
          '-----------------------------------------------------------------------------------------------------------------
          FUNCTION BrowseForFolderProc (BYVAL hWnd AS DWORD, BYVAL wMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG
          
             LOCAL szBuffer AS ASCIIZ * %MAX_PATH
          
             IF wMsg = %BFFM_INITIALIZED THEN
                SendMessage hWnd, %BFFM_SETSELECTION, %TRUE, lParam
             ELSEIF wMsg = %BFFM_SELCHANGED THEN
                SHGetPathFromIDList BYVAL wParam, szBuffer
                IF ISFALSE wParam OR _                            ' No id number
                   ISFALSE LEN(szBuffer) OR _                     ' No name
                   ISFALSE (GETATTR(szBuffer) AND %SUBDIR) OR _   ' Not a real subdir
                   MID$(szBuffer, 2, 1) <> ":" THEN               ' Not a local or mapped drive
                     SendMessage hWnd, %BFFM_ENABLEOK, %FALSE, %FALSE
                     BEEP
                 ELSEIF (GETATTR(szBuffer) AND %SYSTEM) AND RIGHT$(szBuffer,2) <> ":\" THEN ' exclude system folders, allow root directories
                   SendMessage hWnd, %BFFM_ENABLEOK, %FALSE, %FALSE
                   BEEP
                 END IF
             END IF
          
          END FUNCTION
          '-----------------------------------------------------------------------------------------------------------------
          FUNCTION BrowseForFolder (hWnd AS DWORD, strTitle AS STRING, StartFolder AS STRING) AS STRING
          
             LOCAL szBuffer   AS ASCIIZ * %MAX_PATH
             LOCAL bi         AS BROWSEINFO
             LOCAL lpIDList   AS LONG
          
             bi.hWndOwner    = hWnd
             bi.lpszTitle    = STRPTR(strTitle)
             bi.ulFlags      = %BIF_RETURNONLYFSDIRS OR %BIF_DONTGOBELOWDOMAIN OR %BIF_USENEWUI OR %BIF_RETURNFSANCESTORS
             bi.lpfnCallback = CODEPTR(BrowseForFolderProc)
             bi.lParam       = STRPTR(StartFolder)
             lpIDList        = SHBrowseForFolder(bi)
          
             IF ISTRUE lpIDList AND SHGetPathFromIDList(BYVAL lpIDList, szBuffer) THEN
                FUNCTION = szBuffer
                CoTaskMemFree lpIDList
             END IF
          
          END FUNCTION
          '-----------------------------------------------------------------------------------------------------------------
          FUNCTION CheckAttr(dwAttributes AS DWORD, lAttrib AS LONG) AS LONG
          
              LOCAL fRet  AS LONG
          
              fRet = %FALSE
          
              IF (dwAttributes AND lAttrib) = lAttrib THEN
                  fRet = %TRUE
              END IF
          
              FUNCTION = fRet
          
          END FUNCTION
          '-----------------------------------------------------------------------------------------------------------------
          FUNCTION FormatDateTime(inDate AS FILETIME) AS STRING
          
              LOCAL ft        AS FILETIME
              LOCAL st        AS SYSTEMTIME
              LOCAL LCID      AS LONG
              LOCAL dwFlags   AS DWORD
              LOCAL lpFormat  AS ASCIIZ * 40
              LOCAL lpDateStr AS ASCIIZ * 100
              LOCAL cchDate   AS LONG
              LOCAL lpTimeStr AS ASCIIZ * 100
              LOCAL cchTime   AS LONG
              LOCAL sRet      AS STRING
          
              LCID = %LOCALE_SYSTEM_DEFAULT
              lpFormat = "dddd',' MMMM',' dd',' yyyy"
              cchDate = 100
          
              FileTimeToLocalFileTime inDate, ft
              FileTimeToSystemTime ft, st
          
              GetDateFormat LCID, dwFlags, st, lpFormat, lpDateStr, cchDate
          
              lpFormat = "hh':'mm':'ss tt"
              cchTime = 100
          
              GetTimeFormat LCID, dwFlags, st, lpFormat, lpTimeStr, cchTime
          
              sRet = lpDateStr + ", " + lpTimeStr
          
              FUNCTION = sRet
          
          END FUNCTION
          '-----------------------------------------------------------------------------------------------------------------
          Adam Drake
          Drake Software

          Comment


          • #6
            Thanx Adam,
            and WICKED FAST too! :top:
            Engineer's Motto: If it aint broke take it apart and fix it

            "If at 1st you don't succeed... call it version 1.0"

            "Half of Programming is coding"....."The other 90% is DEBUGGING"

            "Document my code????" .... "WHYYY??? do you think they call it CODE? "

            Comment


            • #7
              Thanks for the tip Clay. I was doing some Google searches when Adam was kind enough to post an example.

              Adam, I had to do some mods to suit my CC3.04 and I wanted all files, hidden and otherwise so I deleted all references to it. Also, your example seemed to return unexpected values and my mods appears to have fixed it.

              Anyway, here's what I came up with. Posting just the modified function.
              Code:
              FUNCTION FolderByteCount(inFolder AS STRING) AS QUAD
                  LOCAL SH    AS DWORD
                  LOCAL WFD   AS WIN32_FIND_DATA
                  LOCAL fSpec AS ASCIIZ * %max_path
                  LOCAL qRet  AS QUAD
                  LOCAL qFS   AS QUAD
              
                  IF RIGHT$(fSpec, 1) <> "\" THEN fSpec = fSpec + "\"
              
                  fSpec = infolder + "*.*"
                  SH = FindFirstFile(fSpec, WFD)
              
                  DO
                  qRet = qRet + (wfd.nFileSizeLow + wfd.nFileSizeHigh)
                  LOOP WHILE FindNextFile(SH, WFD)
                  FindClose SH
                  FUNCTION = qRet
              END FUNCTION
              Thanks all.
              There are no atheists in a fox hole or the morning of a math test.
              If my flag offends you, I'll help you pack.

              Comment


              • #8
                Mel, did you mean this?
                Code:
                    IF RIGHT$(inFolder, 1) <> "\" THEN inFolder = inFolder + "\"

                Comment


                • #9
                  Mel, did you mean this?
                  Yea. Probably. Oops!
                  There are no atheists in a fox hole or the morning of a math test.
                  If my flag offends you, I'll help you pack.

                  Comment


                  • #10
                    Hey again Mel. One other quick item: wfd.nFileSizeHigh I believe is the high DWORD of the quad file size, which means it would need to be multiplied by &h100000000--like a SHIFT LEFT 32 would do--if you have files that exceed a DWORD in size. I tested this only indirectly since I can't exceed the DWORD file size, but maybe someone can verify it (or correct it ). This following code would result:

                    Code:
                    qRet = qRet + (wfd.nFileSizeLow + wfd.nFileSizeHigh * &h100000000)
                    btw, your code is faaast, whoof.

                    Comment


                    • #11
                      Here is the code I tested.

                      Code:
                      #COMPILE EXE
                      #DIM ALL
                      #INCLUDE "win32api.inc"
                      
                      FUNCTION FolderByteCount(inFolder AS STRING) AS QUAD
                          LOCAL SH    AS DWORD
                          LOCAL WFD   AS WIN32_FIND_DATA
                          LOCAL fSpec AS ASCIIZ * %max_path
                          LOCAL qRet  AS QUAD
                          LOCAL qFS AS QUAD
                      
                          IF RIGHT$(inFolder, 1) <> "\" THEN inFolder = inFolder + "\"
                      
                          fSpec = infolder + "*.*"
                          SH = FindFirstFile(fSpec, WFD)
                      
                          DO
                          qRet = qRet + (wfd.nFileSizeLow + wfd.nFileSizeHigh * &h100000000)
                          LOOP WHILE FindNextFile(SH, WFD)
                          FindClose SH
                          FUNCTION = qRet
                      END FUNCTION
                      
                      FUNCTION PBMAIN () AS LONG
                          LOCAL lineo AS STRING, tSiz AS QUAD
                          LOCAL q2, q1 AS QUAD
                          lineo = "c:\"     'try a bunch of different directories here
                          queryPerformanceCounter q1
                          tSiz = FolderByteCount(lineo)
                          queryPerformanceCounter q2
                          ? STR$(q2 - q1)
                          ? STR$(tSiz)
                      
                      END FUNCTION

                      Comment


                      • #12
                        ...One other quick item: wfd.nFileSizeHigh I believe is the high DWORD...
                        Don't ask me about that John. All I did was copy Adams code which is about all I can do with API coding. Most of that stuff is pretty much Greek to me.

                        BTW: I did test both forms in several subdirectories and both returned the exact same answer each time. (maybe DwordHigh is zero. Don't know.)
                        There are no atheists in a fox hole or the morning of a math test.
                        If my flag offends you, I'll help you pack.

                        Comment


                        • #13
                          Mel, I'm not totally sure on the math of combining the low and high DWORD values (glad John is, my brain cannot think about that late) - but, there is a function here: http://www.powerbasic.com/support/pb...ghlight=makqud

                          That will convert two DWORDs to a QUAD (equivalent to PBWIN 8+, MAK(QUAD...))
                          Last edited by Adam J. Drake; 5 Jan 2008, 11:04 PM.
                          Adam Drake
                          Drake Software

                          Comment


                          • #14
                            Okay. And here's the final (I hope) version.
                            Code:
                            #INCLUDE "WIN32API.INC"
                                DECLARE FUNCTION FolderByteCount(inFolder AS STRING, mask AS STRING) AS QUAD
                                DECLARE FUNCTION makqud(DWORD, DWORD) AS QUAD
                            
                            FUNCTION PBMAIN () AS LONG
                                LOCAL path AS STRING
                                LOCAL mask AS STRING
                                GLOBAL f AS STRING
                            
                                f = "###,###,###,###"
                                COLOR 14,1
                                CLS
                                path = "c:\windows\system32\"
                                mask = "*.*"
                            
                                COLOR 14,1
                                CLS
                                LOCATE 2,1 : PRINT;path + mask
                                LOCATE 5,1 : PRINT;USING$(f,folderbytecount(path, mask))
                                WAITKEY$
                            END FUNCTION
                            
                            FUNCTION FolderByteCount(inFolder AS STRING, mask AS STRING) AS QUAD
                                LOCAL SH    AS DWORD
                                LOCAL WFD   AS WIN32_FIND_DATA
                                LOCAL fSpec AS ASCIIZ * %max_path
                                LOCAL qRet  AS QUAD
                                LOCAL qFS   AS QUAD
                            
                                IF RIGHT$(inFolder, 1) <> "\" THEN InFolder = InFolder + "\"
                            
                                fSpec = infolder + mask
                                SH = FindFirstFile(fSpec, WFD)
                            
                                DO
                                qRet = qRet + makqud(wfd.nFileSizeLow, wfd.nFileSizeHigh)
                                LOOP WHILE FindNextFile(SH, WFD)
                            
                                FindClose SH
                                FUNCTION = qRet
                            
                            END FUNCTION
                                                                            '
                            'Lifted from: Adam J. Drake at
                            'http://www.powerbasic.com/support/pbforums/showthread.php?t=17087
                            
                            FUNCTION makqud(dwlo AS DWORD, dwhi AS DWORD) AS QUAD
                                #REGISTER NONE
                            
                                LOCAL qret  AS QUAD
                            
                                !pushad
                                !cld
                                !lea    edi, qret
                                !mov    eax, dwlo
                                !mov    eax, [eax]
                                !stosd
                                !mov    eax, dwhi
                                !mov    eax, [eax]
                                !stosd
                                !popad
                            
                                FUNCTION=qret
                            END FUNCTION
                            There are no atheists in a fox hole or the morning of a math test.
                            If my flag offends you, I'll help you pack.

                            Comment


                            • #15
                              I tested
                              Code:
                                 qRet = qRet + (wfd.nFileSizeLow + wfd.nFileSizeHigh * &h100000000)
                              and
                              Code:
                                 qRet = qRet + makqud(wfd.nFileSizeLow, wfd.nFileSizeHigh)
                              and they matched in all cases (20+ billion tested) up to file sizes of 9.22x10^18 (9 billion billion) bytes. I think we can safely say both methods are correct now and will perform admirably for years to come.

                              Comment


                              • #16
                                Originally posted by John Gleason View Post
                                I tested
                                Code:
                                   qRet = qRet + (wfd.nFileSizeLow + wfd.nFileSizeHigh * &h100000000)
                                and
                                Code:
                                   qRet = qRet + makqud(wfd.nFileSizeLow, wfd.nFileSizeHigh)
                                and they matched in all cases (20+ billion tested)....can safely say both methods are correct now and will perform admirably for years to come.
                                What "both" methods?

                                If you take a look at how binary integers are formed, it's pretty obvious these are the same method and 20+ billion tests were not really necessary.

                                Looking at the other thead I'm amazed no one came up with the real easy method which does not require assembly language...
                                Code:
                                FUNCTION makQud (Lo AS LONG, Hi As LONG) AS QUAD
                                
                                 LOCAL W AS QUAD
                                 W            = Hi
                                 SHIFT LEFT W, 32
                                 FUNCTION = W + LO
                                END FUNCTION
                                This is also the same method ... if you take a look at how binary integers are formed.

                                I guess fundamentals are a luxury these days.
                                Michael Mattias
                                Tal Systems Inc. (retired)
                                Racine WI USA
                                [email protected]
                                http://www.talsystems.com

                                Comment


                                • #17
                                  SHIFT LEFT W, 32
                                  I did look at the SHIFT LEFT earlier, but for simplicity, speed, no assembler, and indeed, one less function needed, I thought the best method would be multiplication by &h100000000.

                                  Comment


                                  • #18
                                    There is no one "best" method...for anything.

                                    Optimization is always application-specific. (Another fundamental principle).
                                    Michael Mattias
                                    Tal Systems Inc. (retired)
                                    Racine WI USA
                                    [email protected]
                                    http://www.talsystems.com

                                    Comment


                                    • #19
                                      Another one using pointer to play with FileSizeHigh...

                                      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
                                      '______________________________________________________________________________

                                      Comment

                                      Working...
                                      X