Announcement

Collapse
No announcement yet.

Size of a Folder

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

  • Borje Hagsten
    replied
    been away for a while. guess problem is solved by now, but anyway,
    a while ago i posted another sample, doing exactly this to: http://www.powerbasic.com/support/pb...ad.php?t=23056


    ------------------

    Leave a comment:


  • Gregery D Engle
    replied
    After it gpf'd I decided to simply do this:

    shell "cmd.exe /c dir uncpath /s >c:\tmp.tmp"

    and then parse tmp.tmp

    It works perfectly on win2k

    ------------------
    -Greg

    Leave a comment:


  • Peter P Stephensen
    replied
    Greg

    Did you solve the gpf problem?

    Peter

    ------------------
    [email protected]

    Leave a comment:


  • Peter P Stephensen
    replied
    Gregery

    Are you sure you are using version 3 of ScanDir.inc and my last
    example? I have no problems. I (and others) have used the original
    code 100's of times without gpf's.

    Regards
    Peter

    ------------------
    [email protected]

    Leave a comment:


  • Gregery D Engle
    replied
    Peter,

    I ran your code, and it gpf'd on a unc path and my winnt and winnt\system
    directory.

    ------------------
    -Greg

    [This message has been edited by Gregery D Engle (edited August 28, 2001).]

    Leave a comment:


  • Peter P Stephensen
    replied
    gregery,

    your question made me realize that a more general formulation
    of scandir.inc could speed up the scan. here is the code using
    version 3 of scandir.inc

    regards
    peter

    Code:
    #compile exe
    #include "win32api.inc"
    #include "scandir.inc" ' download: [url="http://www.powerbasic.com/support/pbforums/showthread.php?t=23120"]http://www.powerbasic.com/support/pbforums/showthread.php?t=23120[/url] 
     
    $targetfolder = "c:\winnt" 
    global foldersize as ext
     
    ' user-defined callback function defining the criteria of the scan
    function scanfunc(wfd as win32_find_data) as long
        foldersize = foldersize + wfd.nfilesizelow
    end function
     
    function pbmain
        scandir $targetfolder, codeptr(scanfunc), %true
        msgbox "size of folder '" + $targetfolder + "' is " + format$(foldersize) + " bytes"
    end function
    ------------------
    [email protected]

    Leave a comment:


  • Peter P Stephensen
    replied
    gregery

    try this one:

    regards
    peter

    Code:
    #compile exe
    #include "win32api.inc"
    #include "scandir.inc" ' download: [url="http://www.powerbasic.com/support/pbforums/showthread.php?t=23120"]http://www.powerbasic.com/support/pbforums/showthread.php?t=23120[/url] 
     
    $targetfolder = "c:\winnt" 
    global foldersize as ext
     
    ' user-defined callback function defining the criteria of the scan
    function scanfunc(byval file as string, byval path as string) as long
     
        local hfile as long, fd as win32_find_data
     
        hfile    = findfirstfile(path + "\" + file, fd )
        if hfile = %invalid_handle_value then exit function
        findclose hfile
      
        foldersize = foldersize + fd.nfilesizelow
     
    end function
     
    function pbmain
     
        scandir $targetfolder, codeptr(scanfunc), %true
        msgbox "size of folder '" + $targetfolder + "' is " + format$(foldersize) + " bytes"
      
    end function
    ------------------
    [email protected]

    Leave a comment:


  • Per Fimmeland
    replied
    hi,
    borje hagsten posted some code a while ago, take a look at http://www.powerbasic.com/support/pb...ad.php?t=23275

    -p


    ------------------

    Leave a comment:


  • Scott Turchin
    replied
    Short of doing a DIR on the entire file, I would take this function and run with it, but I do not know if there is a piece of the TYPE you can use to get that.
    You may have to do a DIR (I have the code for it).

    Code:
    Function FolderExists(ByVal FolderSpec As String) Export As Long
      Local hDir     As Long
      Local FindData As WIN32_FIND_DATA
    
      FindData.dwFileAttributes = %FILE_ATTRIBUTE_DIRECTORY
      hDir = FindFirstFile(ByVal StrPtr(FolderSpec), FindData)
      If Bit(FindData.dwFileAttributes, 4) = 1 Then Function = %TRUE
      If hDir = %INVALID_HANDLE_VALUE Then
        Exit Function     'file not found
      End If
      FindClose hDir
    End Function
    
    '
    '
    '
    'If that fails, go with this....I would test it, I can't remember if it's 100% functional but I think it is....
    You'll need to do subfolders as well..
    Function GetDirList(CurrentDir As String,wFileSpec As String,LfnOrSfn As Long) Export As String
    Local x        As Long
    Local wCount   As Long
    Local hDir     As Long
    Local f        As String
    Local sTmp     As String
    Local St       As String
    Local ShortName As Asciiz * 64
    Local LongName As Asciiz * 64
    
    Local l_FileSpec As String
    Local FindData As WIN32_FIND_DATA
    
    If Len(wFileSpec) = 0 Then
        If Right$(CurrentDir,1) = "\" Then CurrentDir = Left$(CurrentDir,Len(CurrentDir) - 1) 'Remove rigt "\"
        l_FileSpec = CurrentDir + "\*.*"
    Else
       l_FileSpec = CurrentDir + "\" + wFileSpec
    End If
    
    FindData.dwFileAttributes = %FILE_ATTRIBUTE_DIRECTORY
    hDir = FindFirstFile(ByVal StrPtr(CurrentDir), FindData)
    If hDir = %INVALID_HANDLE_VALUE Then 'Directory did not exist
        Function = "File or directory does not exist"
        Exit Function
    Else
        sTmp = "Directory of " + CurrentDir + "\" + $CRLF
        FindData.dwFileAttributes = %FILE_ATTRIBUTE_NORMAL Or %FILE_ATTRIBUTE_ARCHIVE Or %FILE_ATTRIBUTE_READONLY
        hDir = FindFirstFile(ByVal StrPtr(l_FileSpec), FindData)
        If IsFalse LfnOrSfn Then 'Use Long File Name otherwise use short name
           LongName = FindData.cFileName
           GetShortPathName LongName,ShortName, 63
           FindData.cFileName = ShortName
        End If
    
        If hDir = %INVALID_HANDLE_VALUE Then
           Function = "File not found"
           Exit Function
        End If
        Do
           If FindData.cFileName = "." Or FindData.cFileName = ".." Then Iterate
           Incr wCount
           If FindData.dwFileAttributes = %FILE_ATTRIBUTE_DIRECTORY Then
                   If IsFalse LfnOrSfn Then 'Use Long File Name
                      LongName = FindData.cFileName
                      If IsTrue GetShortPathName(LongName,ShortName, 63) Then FindData.cFileName = ShortName
                   End If
                   FindData.cFileName = "<" + FindData.cFileName + ">"
            Else
                   sTmp = sTmp + PadString(Left$(FindData.cFilename,25),25,32) + " " + _
                          PadString(Format$(FindData.nFileSizeLow,"###,###,###"),15,32) + " " + _
                          padstring(FileDateTime(FindData),15,32) + $CRLF
            End If
    
        Loop While FindNextFile(hDir, FindData)
    End If
    FindClose hDir
    Function = sTmp
    End Function
    
    '-----------------------------------------------------------------------------------

    ------------------
    Scott Turchin
    MCSE, MCP+I
    Computer Creations Software
    http://www.tngbbs.com/ccs

    Leave a comment:


  • Gregery D Engle
    replied
    I was hoping for some windows code that would work with a UNC path.

    I thought maybe an API existed for this.

    ------------------
    -Greg

    Leave a comment:


  • Tom Hanlin
    replied
    There's PB/DOS source code for that in Randall L. Glass' 4dirsize.zip.
    See http://www.powerbasic.com/files/pub/pbdos/tools/

    ------------------
    Tom Hanlin
    PowerBASIC Staff

    Leave a comment:


  • Gregery D Engle
    started a topic Size of a Folder

    Size of a Folder

    Anybody have some quick and dirty code to determine the size of
    a given folder? I need to setup some monitoring of User's Home
    Drives for audting purposes.

    ------------------
    -Greg
Working...
X
😀
🥰
🤢
😎
😡
👍
👎