Link to home
Start Free TrialLog in
Avatar of David777
David777

asked on

How can I get a folder's attribute like size and so on and quote it in VB

Dear all,

I want to sort all subfolders by size under a folder. But I don't know how I can get it and quote it in VB.
any suggestion will be highly appreciated.

David777
Avatar of gron
gron
Flag of Canada image

There may be a more elegant way, but one suggestion would be to loop through the files in the folder and subfolders and add up their length using the FILELEN command, as in :

Pathname = "D:/My Documents/ReadMe.txt"
a = FileLen(Pathname)
ASKER CERTIFIED SOLUTION
Avatar of RichW
RichW
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Opps!  take out the ctr and ctr2 and lngSize and "Whoohoo!".  I used them for testing.
Avatar of Richie_Simonetti
hearing...
Any progress?
Avatar of mksilk
mksilk

RichW,

I am attempting to use your code but am receiving the following error:
"Compile error: User-defined type not defined"
This occurs on the line of code:

Dim fso as Scripting.FileSystemObject

Any ideas why??
you have to set a reference to microsoft scrypting in your project.
Go to project/references... menu and locate that library. Do a check mark and push OK button.
Cheers
I originally said to set a reference to the Microsoft Scripting Runtime object.  

You can't use the FileSystemObject without setting a reference to it first.

Thanks, Richie.
:)
You are welcome.
By the way, i prefer to use references but using CreateObject, reference is not necessary.
Cheers
Hi David777,
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:

    Accept RichW's comment(s) as an answer.

David777, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange