Extract .txt files from a list
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Yewande Oni
am 9 Jun. 2015
Kommentiert: Yewande Oni
am 11 Jun. 2015
Hi,
I am trying to extract .txt files from a list of files I created into a cell array. From there I want to put them in a directory that feeds into a loop. Can you help please?
Thanks
3 Kommentare
Walter Roberson
am 9 Jun. 2015
Yes, and notice that the ext will include the '.' so Adam is correct in saying to compare against '.txt' rather than 'txt'
Akzeptierte Antwort
Walter Roberson
am 10 Jun. 2015
If YourCell is a cell array of strings that represent file names, then
is_txt_file = ~cellfun(@isempty, regexp(YourCell, '\.txt$'));
this will give you a logical vector that you can use such as
txtFileNames = YourCell(is_txt_file);
After that you can process them however you like.
If what you have is a dir() result and you want to pick out the txt files from that, then supposing DirInfo is the directory structure,
YourCell = {DirInfo.name};
is_txt_file = ~cellfun(@isempty, regexp(YourCell, '\.txt$'));
txtDirInfo = DirInfo(is_txt_file);
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu File Operations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!