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
165 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
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

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

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…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month5 days, 6 hours left to enroll

626 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