I'm wildly speculating about what you want the inner loop to do here, but your problem description sounds like the above would be closer to what you really want than what you have now. Perhaps you can explain in more detail what input file looks like, and what you want to extract from it.
My outer loop is just taking one file at a time from the specified directory.
My second loop is taking that file and doing some search operation based on some criteria.
I tested the second loop alone and it is working fine. Just having problem to put an outer loop which ll give one by one file name to the second loop.