Try a search on the "directory listing"-subject. There are a lot of post on this on this forum, and I successfully made a function for this myself about a couple of months ago after a quick search on "directory AND list" or something like that...
I suggest a simple conditional statement to insert the filename/fileinfo to the database.