Let's say I have a folder
First, use your recursive directory scanner to scan all of the
folder_2 directory tree. Build a hash table that contains the file names, without the
folder_2 prefix. So your hash table would contain:
/dir_1 /dir_1/file_1_1.txt /dir_1/default.txt /dir_2/file_2_1.txt /dir_2/default.txt /default.txt
Now, start scanning
folder_1. When you get a file, strip
folder_1 from the front, and look for the resulting string in the hash table. If it's there, then you have a match.
If the file is not there, replace the last segment with "default.txt", and try again. So, when you begin scanning
folder_1, you get:
You look up
dir_1/file_1_1.txt in the hash table and find it. You have a match.
Next, you get
/folder_1/dir_1/file_1_2.txt. You look up
/dir_1/file_1_2.txt in the hash table and don't find it. So you replace
default.txt, giving you
/dir_1/default.txt. You look that up in the hash table, find it, and you have a match.
/dir_1/default.txt did not exist, then you would again adjust the file name to remove the last directory. That is, you'd remove
/dir_1, and you'd look up
/default.txt in the hash table.
In pseudo code it looks like this:
for each file in folder_1 name = strip `/folder_1` from the name if name in hash table then match found continue (next file) end if replace file name (everything after the last '/') with "default.txt" do if name in hash table then match found continue (next file) end if remove the last slash, and everything between it and the previous slash. (so "/dir_1/default.txt" becomes "/default.txt") while name.length > 0 // if you get here, no match was found end for