Поиск конкретного файла в папке отсортированного файла - PullRequest
0 голосов
/ 04 марта 2019

У меня есть папка с различными расширениями файлов, например .txt, .xls.

Файлы имеют имена в следующем порядке:

  • 20190228_0_20_20
  • 20190228_50_20_50

Я перебрал все файлы с расширением .txt.В этой отсортированной папке я хотел бы найти конкретный файл с именем 20190218_0_20_20 и загрузить его, а затем выполнить некоторые вычисления.Вот мой код

Заранее большое спасибо:

%processing the parent folder

myfolder ='C:\Users\yannick\Desktop\Windkanal_Data\Yannick';

if~isdir(myfolder)
    Error_message =sprintf('Error,Folder not found :\n %s',myfolder);
end

%Getting list of all files with  file pattern .txt

filepattern =fullfile(myfolder,'*.txt');

txtfiles=dir(filepattern);

%sorting out the file with name  20190228_0_20_20 .txt 

1 Ответ

0 голосов
/ 04 марта 2019

Хм, мы должны применить некоторые довольно дикие предположения о том, что вы пытаетесь сделать здесь, но я попробую:

% dir only those that match your format
filepattern =fullfile(myfolder,'20190228_0_*_*.txt'); 
% get all matching files
txtfiles=dir(filepattern);
% let's loop them
for iFile = 1:length(txtfiles)
    % extracting the x and y from the file name of the current file
    fn_parts = split(f(iFile).name,{'_','.'});
    coor_x = str2double(fn_parts{3});
    coor_y = str2double(fn_parts{4});
    % now you know the coordinates (x,y) that belong to the current file. You can use this to search for a specific coordinate if you like (though it would be easier to do this earlier I guess)
    % next step is reading it I guess. I have no idea about your file format. Try dlmread? importdata?
    fcontents = importdata(fullfile(f(iFile).folder,f(iFile).name)); 
    % process further...

end
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...