Solved

Counting folders that have similar names in VB6

Posted on 2006-07-20
4
205 Views
Last Modified: 2010-04-30
Hello,

I am writing a program that selects and moves folders from one location to another using VB6.
Both source and destin locations are local (c: drive).
When I select the folders to be moved, I provide a pattern which is the first numeric part of each folder name.
Let's say I provide "123456", then any folder name that starts with this number is going to be moved.
I used MoveFolder method of filesystemobject to move folders.
This was working fine for me because it takes wild character (123456*) and moves all the folders whose names start with that number that I provide.

Now, I need to count the number of folders moved related with each number (123456 in this case).
Unfortunately MoveFolder method doesn't look like providing this number.
And I have about 1000 numbers that I have to process at a time.

What is the most efficient way to get the count of the folders that has the same first part pattern in their name?

Thanks for your help.
0
Comment
Question by:JOSHUABT
  • 2
4 Comments
 
LVL 12

Accepted Solution

by:
jkaios earned 300 total points
ID: 17150159
You can do something like this:

Private Sub Command1_Click()
  MsgBox "Folder Count: " & GetFolderCount("C:\123456*")
End Sub

'=================================================
Public Function GetFolderCount(sPath As String, sPattern As String) As Long

  Dim xx As String
  Dim ii As Long
 
  xx = Dir(sPath & "\" & sPattern, vbDirectory)
 
  Do Until xx = ""
    If Len(xx) And (GetAttr(sPath & "\" & xx) = vbDirectory) Then
       ii = ii + 1
       Debug.Print "[" & xx & "]"
    End If
    xx = Dir()
  Loop
 
  GetFolderCount = ii
 
End Function
'=================================================
0
 
LVL 15

Assisted Solution

by:Ryan_R
Ryan_R earned 200 total points
ID: 17151592
i would put an invisible File box on your form and use something like this:

-----
Dim nFirstCount as Integer, nSecondCount as Integer, nMoveFolderCount as Integer
nFirstCount = 0
nSecondCount = 0
nMoveFolderCount = 0
File1.Path = <Destination path for move method>
nFirstCount = File1.ListCount
<Call your move/copy method here>
File1.Refresh
nSecondCount = File1.ListCount
nMoveFolderCount = nSecondCount - nFirstCount
--------

what do you think?

Ryan R
0
 

Author Comment

by:JOSHUABT
ID: 17226280
Sorry for late response.
I used Dir function as jkaios suggested and it works.
But Ryan's idea to use invisible File box is another idea, I think.

I will split the points.

Thanks
0
 
LVL 15

Expert Comment

by:Ryan_R
ID: 17230644
thanks for the points.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…

896 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now