Solved

Need to rename Folders by swapping first and last names

Posted on 2010-08-23
5
427 Views
Last Modified: 2012-05-10
Using Visual Studio 2008
Visual Basic.net


I have 40,000 folders each with a employee name.
The way it was setup orignally was was "First Name Last Name" Like "Cindy Jones"

However some of the names include middle initials (in some cases multiple initials)  and "jrs"

Like "Brian W. H. Marks Jr"

I need to swap first and last name order for all the folders (rename them and add a comma)
I can do the simple names but I am having trouble with the middle initials and suffixes.

How can I swap:

Brian W. I. Marks Jr
to
Marks, Brian W. I.  (Jr is irrelevant)

and
Cindy A. Jones
to
Jones, Cindy

And recourse all the directories of a specified folder?

(Note: I do NOT need to rename any files or folders under the original subfolder listing of 40K folders.)
0
Comment
Question by:EGormly
5 Comments
 
LVL 3

Expert Comment

by:ianmair329
ID: 33503006
You will need to create some rules for the renaming.
I would try detecting the presence of the full stop and use that as the basis.

You could either use regular expressions or the Split function. You could split on the "." and then split on the space, then that would split up all the sections.

If nobody else comments i'll have a go at the function for you later
0
 

Author Comment

by:EGormly
ID: 33503053
I was splitting on the space and then trying to loop it to find other parts of the "first" name.

I ust can't seem to loop it properly, the strip is all fubar.
0
 
LVL 92

Assisted Solution

by:Patrick Matthews
Patrick Matthews earned 200 total points
ID: 33503158
EGormly,You may want to have a look at this article:http://www.experts-exchange.com/Programming/Languages/Visual_Basic/A_1819-Parsing-Names-in-MS-Office-Visual-Basic-6-and-Visual-Basic-for-Applications.htmlIt is focused on VB6/VBA and not VB.Net, but the basic strategy of using RegExp may still be useful for you.Patrick
0
 
LVL 13

Accepted Solution

by:
Jesus Rodriguez earned 300 total points
ID: 33503255
Look at this code. I try with the two names and works find


        Dim FolderName As String

        Dim I, CDots, Lpos

        CDots = 0

        Lpos = 0

        FolderName = Me.TextBox1.Text

        Dim CSuffix(3)

        CSuffix(1) = "Jr"

        CSuffix(2) = "Mr"

        CSuffix(3) = "Mrs"

        For I = 1 To 3

            FolderName = Microsoft.VisualBasic.Strings.Replace(FolderName, CSuffix(I), "")

        Next I

        'Count the Dots in the string

        For I = 1 To Len(FolderName)

            If Mid(FolderName, I, 1) = "." Then

                CDots += 1

                Lpos = I

            End If

        Next

        Dim NewFolderName

        If Lpos > 0 Then

            NewFolderName = Microsoft.VisualBasic.Right(FolderName, Len(FolderName) - Lpos - 1) + "," + Mid(FolderName, 1, Lpos)

        Else

            'put the procedure for the regulars



        End If

        Me.label1.text = NewFolderName

Open in new window

0
 

Author Closing Comment

by:EGormly
ID: 33504167
Thank to you both. The code example was great K-designers and matthewspatrick, that link was very informative!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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…

743 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