Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Counting folders that have similar names in VB6

Posted on 2006-07-20
4
Medium Priority
?
212 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 1200 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 800 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

885 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