in reply to READDIR and DBI
Maybe bulkloading is easier; most DBs have a way to bulkload, for instance postgres:
ls -1v *.txt | psql -c " create table if not exists t(filename text); copy t from stdin; " [download]