Solved

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

Posted on 2014-02-06
6
230 Views
Last Modified: 2014-02-08
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.
0
Comment
Question by:Uptime Legal Systems
  • 3
  • 3
6 Comments
 
LVL 22

Assisted Solution

by:rspahitz
rspahitz earned 500 total points
ID: 39841019
This can be done relatively easily in Excel after you import the list (or otherwise use a VBA to load the contents into a spreadsheet.)
After you have the data in place (e.g. columns A and B) you can add a formula in column C to tell you if each entry in column A exists in column B.

C1 formula =IF(ISNA(MATCH(A1,B:B,0)),"missing " & A1,"")

That should take care of one part of the request: identifying folders in A that are not in B

Does that help?
0
 
LVL 6

Author Comment

by:Uptime Legal Systems
ID: 39841763
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.)
0
 
LVL 22

Accepted Solution

by:
rspahitz earned 500 total points
ID: 39842239
So you're looking for something that lets you manually connect items in A with items in B and have a tool put those connections in a CSV file?
Since there are no tools I know to let you do this, one could be written, but that makes your entire request a bit bigger than a simple task.

Is it a one-time process or will this be repeated over and over?
Are you OK using Excel to do this? Maybe you want a more permanent tool written in VB.Net?  (Do you have either Excel or VB.Net or do you have an interest in getting VB.Net on your system?)

In Excel, I would write some VBA to let you click on two cells and have it build the relationship for you, which can then be written to a CSV file when done.
In VB.Net, I'd probably let you do a drag-and-drop of one file name onto another to build the links.

After the mapping is done, renaming the parts and relocating the unmatched items would be relatively easy in either tool.
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 6

Author Comment

by:Uptime Legal Systems
ID: 39842565
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.
0
 
LVL 6

Author Closing Comment

by:Uptime Legal Systems
ID: 39843009
I'll dig in and see what I can come up with.  Appreciate the advice from both.
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 39844503
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

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

705 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

13 Experts available now in Live!

Get 1:1 Help Now