One way to solve the problem is that your code can try to find mydir in /usr/share/ first. If mydir is not there, your code tries /usr/local/share/. If /usr/share/ and /usr/local/share/ both have mydir, your code can still detect which is the right one.