Link to home
Start Free TrialLog in
Avatar of Uptime Legal Systems
Uptime Legal SystemsFlag for United States of America

asked on

Script to map folder names to another directory, then rename the source

I'm looking for help with some scripting that would accomplish the following.

Directory A has a series of folders.
Directory B has a series of folders, perhaps more, than DirA.

I would need to be able to pair a folder in DirA with a folder in DirB, and map the results to a .csv which would then rename the folders in DirB to match it's pair in DirA.  Also at this time, any unpaired folder would be moved to a specified location, marked as 'unsorted'.   As you might imagine, I have a large number of folders to merge and would need the names to match to accomplish this.

The primary challenge I am having is the pairing of folders.  I'm not well versed enough to know a clean way to go about this but I think the easiest method would be for each folder in DirA, it would ask for the matching folder name in DirB (which could be typed and finished with the Tab key); but perhaps a script guru might have a better idea.

Appreciate the advice in advance.
SOLUTION
Avatar of rspahitz
rspahitz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Uptime Legal Systems

ASKER

That's a pretty nice formula, I think the problem would be that since the names in A won't be the same as B, it wouldn't match.

I can manually go in and clean out a CSV, but was hopeful there might be a way to get the CSV lists in with the pairing already completed (so it could all be run as part of one script.)
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes, connect items in A with B, based off manual mapping.

It is a process that I would be repeating several times with (tens of) thousands of folders.

I would be completely fine doing this in excel, but my VB script skills aren't quite up to the task.  I can try and 'franken-script' something together and see how it goes, unless you have some insight or a bare bones script to use as reference.
I'll dig in and see what I can come up with.  Appreciate the advice from both.
FYI, the following code will show all folders in a given directory (in this case, the one in the Rob document folder).  the results will be placed in the "immediate" window (Ctrl+G):
Sub showAllFolders()
    Dim path As String
    path = "C:\Users\Rob\Documents"
    Dim file As String
    
    file = Dir(path & "\", vbDirectory)
    Do While file <> ""
        If FileSystem.GetAttr(path & "\" & file) = vbDirectory Then
            Debug.Print file
        End If
        file = Dir
    Loop

End Sub

Open in new window