Hi there, and welcome.
will get your contents of a single directory into a text file, but I don't know about the other part. I think you will have to be more specific so that the other members will know exactly what you are trying to do.
Edit: Hang on, I just read it again, you want to put the filename into the file it belongs to, sorry. The above command won't do that, In fact, just ignore this post.
(I am tired an have a massive headache)
Sorry for any confusion.