Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

GetFolderSize

Posted on 2001-09-04
7
Medium Priority
?
667 Views
Last Modified: 2007-12-19
What is the best API to get Folder size instead of using the API below?


Type FILETIME
    dwLowDateTime As Long
    dwHighDateTime As Long
End Type


Type WIN32_FIND_DATA
    dwFileAttributes As Long
    ftCreationTime As FILETIME
    ftLastAccessTime As FILETIME
    ftLastWriteTime As FILETIME
    nFileSizeHigh As Long
    nFileSizeLow As Long
    dwReserved0 As Long
    dwReserved1 As Long
    cFileName As String * MAX_PATH
    cAlternate As String * 14
End Type


Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
Declare Function GetFileAttributes Lib "kernel32" Alias "GetFileAttributesA" (ByVal lpFileName As String) As Long
Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
0
Comment
Question by:zubairi
7 Comments
 

Expert Comment

by:Wendelldhays
ID: 6455424
As far as the API,

I would use

BOOL GetFileInformationByHandle(
HANDLE hFile,
LPBY_HANDLE_FILE_INFORMATION lpFileInformation);

typedef struct _BY_HANDLE_FILE_INFORMATION {
DWORD dwFileAttributes;
FILETIME ftCreationTime;
FILETIME ftLastAccessTime;
FILETIME ftLastWriteTime;
DWORD dwVolumeSerialNumber;
DWORD nFileSizeHigh;
DWORD nFileSizeLow;
DWORD nNumberOfLinks;
DWORD nFileIndexHigh;
DWORD nFileIndexLow;
} BY_HANDLE_FILE_INFORMATION;

I will let you figure out the Declaration in VB.

But I like to yse the FileSystemObject

Dim oFSO As Object
Dim oF As Object

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oF = fso.GetFile(C:\MyDir\MyFile)
MsgBox oF.size
Set oF = Nothing
Set oFSO = Nothing
0
 

Author Comment

by:zubairi
ID: 6456042
I am not interested in FSO, but i am more interested in API as you declared above. Can you show , how to use the API?

Best Regards,
Zubairi
0
 
LVL 3

Expert Comment

by:Rem
ID: 6456479
Hi,

Don't know for sure this is what you're looking for but ...

This tip demonstrates how to use the Win32 API to bring up the explorer properties dialog box for a specified file.  This API function has the same effect as right clicking on a file in Windows 95 and selecting properties.  The dialog box that is opened is shown below.
Declarations

This following code must be placed in the projects declarations section.

Type SHELLEXECUTEINFO
    cbSize As Long
    fMask As Long
    hwnd As Long
    lpVerb As String
    lpFile As String
    lpParameters As String
    lpDirectory As String
    nShow As Long
    hInstApp As Long
    lpIDList As Long
    lpClass As String
    hkeyClass As Long
    dwHotKey As Long
    hIcon As Long
    hProcess As Long
End Type

Public Const SEE_MASK_INVOKEIDLIST = &HC
Public Const SEE_MASK_NOCLOSEPROCESS = &H40
Public Const SEE_MASK_FLAG_NO_UI = &H400

Declare Function ShellExecuteEX Lib "shell32.dll" Alias _
"ShellExecuteEx" (SEI As SHELLEXECUTEINFO) As Long        

Code

Public Sub ShowProps(FileName As String, OwnerhWnd As Long)
    Dim SEI As SHELLEXECUTEINFO
    Dim r As Long
    With SEI
        .cbSize = Len(SEI)
        .fMask = SEE_MASK_NOCLOSEPROCESS Or _
         SEE_MASK_INVOKEIDLIST Or SEE_MASK_FLAG_NO_UI
        .hwnd = OwnerhWnd
        .lpVerb = "properties"
        .lpFile = FileName
        .lpParameters = vbNullChar
        .lpDirectory = vbNullChar
        .nShow = 0
        .hInstApp = 0
        .lpIDList = 0
    End With
    r = ShellExecuteEX(SEI)
End Sub        

Use

To show the properties dialog box of "c:", use the following code:

Call ShowProps("c:", Me.hwnd)


Courtesy of
Copyright ? 1998-2001, The KPD-Team - Privacy statement

This site is located at http://www.allapi.net/

Bye

Rem
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6458788
All examples that i know manage file attributes, not folders. Sorry.
I only know how to do with FSO :(.
0
 

Author Comment

by:zubairi
ID: 6462726
For those who are not clear my question, Let me explain in detail.


What i am trying to do is to get the folder size by using API method. NOT using File System Object.
Example C:\Data. --> get the size of this folder

I know FSO is an option i can use but, i prefer to use API.

Best Regards,
Zubairi
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7207624
Hi zubairi,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Refund points and save as a 0-pt PAQ.

zubairi, Please DO NOT accept this comment as an answer.
EXPERTS: Post a comment if you are certain that an expert deserves credit.  Explain why.
==========
DanRollins -- EE database cleanup volunteer
0
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
ID: 7240957
Per recommendation, points refunded and question closed.

Netminder
CS Moderator
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question