Solved

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

Posted on 2002-04-21
11
163 Views
Last Modified: 2010-05-02
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
0
Comment
Question by:David777
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 1

Expert Comment

by:gron
ID: 6957610
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)
0
 
LVL 4

Accepted Solution

by:
RichW earned 50 total points
ID: 6957661
Set a reference to the Microsoft Scripting Runtime object.

Place a listbox on a form.

Paste the following into your form's module:

Replace MyFolder witht he folder you wish to target.

This will sort the subfolders according to size.
You can tweak the code to add the folder names, etc.

This will give you an idea of how to grab the attributes of the subfolders.

Good luck!
RichW

Private Sub Form_Load()
Dim fso As Scripting.FileSystemObject
Dim fldr
Dim subFldr
Dim ctr As Long
Dim ctr2 As Long
Dim lngSize As Long
Dim s

Set fso = New Scripting.FileSystemObject
Set fldr = fso.GetFolder("c:\MyFolder")
Set subFldr = fldr.SubFolders

For Each s In subFldr
    Me.List1.AddItem s.Size & "Whoohoo!"
Next
Call sort(Me.List1)

End Sub
Private Function sort(x As ListBox)

 Dim a As String
 Dim z As Integer
 
 For z = 0 To x.ListCount - 2
  If Val(x.List(z)) > Val(x.List(z + 1)) Then
   a = Val(x.List(z))
   x.List(z) = Val(x.List(z + 1))
   x.List(z + 1) = a
   z = 0
  End If
  DoEvents
 Next z
 
End Function

0
 
LVL 4

Expert Comment

by:RichW
ID: 6957663
Opps!  take out the ctr and ctr2 and lngSize and "Whoohoo!".  I used them for testing.
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6958469
hearing...
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 7128828
Any progress?
0
 

Expert Comment

by:mksilk
ID: 7184066
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??
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7185633
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
0
 
LVL 4

Expert Comment

by:RichW
ID: 7185648
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.
:)
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7185875
You are welcome.
By the way, i prefer to use references but using CreateObject, reference is not necessary.
Cheers
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7660610
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
0
 

Expert Comment

by:SpideyMod
ID: 7755180
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Technology Partners: 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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

739 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