You move your code into main to some other function and loop through it recursively to populate for all the directories and sub-directories.