Any instanced node in Maya has multiple parent transforms, therefore, the basic idea to determine the instanced node is to check the number of its parent nodes. However, if we have both instanced shapes and some other transform nodes from the same hierarchy, it gets a little harder to handle this situation just by MEL.
» read more »There is a simple way to traverse a directory tree with python - os.walk
(os.path.walk is deprecated in 3.0, therefore, we had better avoid to use it!)