Link Resolve Brainstorming / Efficiency

This widget could not be displayed.

Link Resolve Brainstorming / Efficiency

Anonymous
Not applicable

I'm doing an open brainstorm right now of how to do this and am simply looking for a more efficient way (if there is one) to find a common suffix of a file. What I'm doing is renaming a set of files (parent project, children files, and chilren's children files), opening the new file, and resolving the links between the parts. Well, that's the basic way to explain it anyways. I'm very excited that I started learning VBA two weeks ago and am already almost done!

 

What I need to do to resolve the links is use the following:

 

Component.Replace("Old Part","New Part",False)


However, the way my files are set up are as follows:

 

Parent:

MyCodeWorks1.ipj

 

Children:

MyCodeWorks1-001.iam

MyCodeWorks1-002.iam

 

Children of Children:

MyCodeWorks1-003.ipt

MyCodeWorks1-004.ipt

MyCodeWorks1-005.ipt

MyCodeWorks1-006.ipt

etc.


I then rename my parent file to, say, "Yay32.ipj". All prefixes "MyCodeWorks" then change to prefix "Yay32". To fit the format for the replace component procedure, I need to grab the suffixes "001","002","003",etc.

 

I have two ideas so far and would love more input. I'm new to VBA and really don't know the most efficient way to do things yet. I'm posting my ideas below! Does anyone have a better or more efficient idea? This is more theoretical; I wouldn't need the actual code, just an idea!

 

1) When the user inputs "Old Name" and "New Name" into the initial renaming process, I could have it calculate the number of characters in each string and then skip that many characters in each to find the common suffix.

2) Search for the full prefix ("001")...this could cause problems because sometimes a file might read, say, SD5 001 - 001 . But maybe there's a way to search for that prefix after the hyphen, adding i=1 each time in a loop?

 

Thanks for any ideas ahead of time!!!

0 Likes
Reply
Accepted solutions (1)
470 Views
2 Replies
Replies (2)

Anonymous
Not applicable

EDIT 1: I've been looking in to the idea of suffix trees. Maybe this could be a better way to go about solving this problem?

EDIT 2: I've looked in to applications of suffix trees, and that seems to be a plausible, if not complicated, solution. There's a similar application starting on slide 14, here:


http://www.cs.uku.fi/~kilpelai/BSA05/lectures/slides08.pdf


The difference would be instead of finding the LONGEST common string, I'd be looking for the LAST common string. Does anyone know of an easier way to do this before I start working on it?

 

 

Additional relevant links. I've also started a discussion on this on StackOverflow. Links HERE and HERE.

0 Likes

Anonymous
Not applicable
Accepted solution

Possible solution, from StackOverflow:

 

"I am not sure a suffix trie would be much more efficient in your case.. You would need to build a map to store all the prefixes etc which depending on the amount of prefixes possible could take longer than just getting on and renaming it one by one. It seems that you are actually complicating and overkilling such a simple procedure. Why don't you use InStr(1, oldName, newName, vbTextCompare)? – mehow"

Link Here

 

 

0 Likes