I have multiple files with the same names in different subfolders. All files are called runoff.txt. The subfolders are called results1, results2, results3 and so on, so they differ only by a consecutive number.
For the import of txt files with the same names from different subfolders, I have tried an approach to solve this issue like mentioned on:
My script looks like:
pathname = 'C:\Users\heute\results\model_standalone\';Mdir = dir(pathname);nbentries = size(Mdir, 1);Mfiles = [];for entry_i = 1:nbentries if Mdir(entry_i).isdir == false filename = Mdir(entry_i).name; if filename(1) ~= '.' [p, n, ext] = fileparts(filename); if strcmpi(ext, '.txt') Mfiles = strvcat(Mfiles, filename); end end end end nbfiles = size(Mfiles, 1);for iFile = 1:length(Mfiles); [Date,QSfirn,QSice,QSrock,QSsnow,QSsoil,Qs]=textread(Mfiles(iFile),'%s %f %f %f %f %f %f',-1,'headerlines',1);end
The program runs without error messages but the txt files are not imported.
For example that the folder model_standalone contains 2 subfolders with the names results1, results2 and within these folders a txt file with the name runoff.txt the following output is returned:
- Mdir: 4×1 struct
- Mfiles: []
- entry_i: 1×1 double
- i: 1X1 double
- nbentries: 1×1 double
- nbfiles: 1×1 double with 0
- pathname: char_
Why aren't the individual txt files recognized?
How can you fix the problem that all txt files from the subfolders are read (perhaps in a different way)?
—–
The same question has already been asked on this page:
but without any problem-solving answer.
—-
For any helpful answer I would be deeply grateful, because this problem prevents all further data evaluation processes. (I'm using Matlab R2012a).
Best Answer