Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Counting folders that have similar names in VB6

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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.
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 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…
Suggested Courses

719 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