- use fullfile instead of strcat to build path names. It's a lot more reliable
- Do you really have a folder called foldername? It's very unusual and I suspect the original intent of the code was to have an arbitrary folder whose name would be stored in a variable called foldername. In which case, the variable name should not be enclosed in quotes
- similarly, are the text files you're trying all named foldernamesomething. Because that's exactly what you're trying to open. Normal code would be: