in reply to Re^2: Case of autovivification
in thread Case of autovivification

You need to decide what you want your data structure to look like before you do anything else. Right now, you're trying to store every non-directory file in directory at the same key as the directory itself.