Solved

Counting folders that have similar names in VB6

Posted on 2006-07-20
4
204 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
thanks for the points.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
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…
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…

771 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

10 Experts available now in Live!

Get 1:1 Help Now