Solved

Counting folders that have similar names in VB6

Posted on 2006-07-20
4
208 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
[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
  • 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…

752 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