Using contains() with dir() to search files in folder
    48 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
%{
trying to figure out how to search a folder for a file that contains a
matching string 
serials is a 1x26 cell 
%}
files_in_folder = dir('folder');
TF = contains(files_in_folder.name, serials);
%{
Error using contains
Incorrect number of arguments. Each parameter name must be followed by
a corresponding value.
%}
TF = contains(files_in_folder.name, serials(1))
%{
Error using contains
Incorrect number of arguments. Each parameter name must be followed by a
corresponding value.
%}
for i = files_in_folder
    if  TF == 1
        File = strcat('example.txt');
    end
end
%{
trying a few different variations:
%}
for i = files_in_folder
                if contains(files_in_folder, serials) == 1
                    disp(serials);
            end
end
for i = files_in_folder.name
                if contains(files_in_folder.name, serials) == 1
                    disp(short_serials);
                end
end
%{
A dot '.' indexing expression produced a comma-separated list with 15
values where only a single value is allowed.
%}
0 Kommentare
Antworten (1)
  Stephen23
      
      
 am 29 Jul. 2022
        
      Bearbeitet: Stephen23
      
      
 am 29 Jul. 2022
  
      Replace this comma-separated list
files_in_folder.name
with this cell array of filenames:
{files_in_folder.name}
S = dir(..);
TF = contains({S.name}, serials);
2 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!