Using regexpressions with 'dir' function
Show older comments
Hi, I have a folder (MainFolder) that contains other subfolders (Subfolder1, Subfolder2, Subfolder3, ....). Each of those subfolders contain different png images. The format of the name of those images is 'somerandomnameOD1.png' or 'somerandomnameOS1.png'. The last number of the names varies from 1 to 6.
I am trying to use dir function with some regexpressions to extract the path of all those images that end with a pattern like 'OD' or 'OS' followed by the number 1, 2 or 6 (OD1, OD2, OD6, OS1, OS2, OS6) from all the subfolders within the 'MainFolder':
a=dir('C:\folder\folder2\Desktop\MainFolder\**/*O(D|S) (1|2|3).png'));
But the result is an empty struct.
I know I can simply use this:
a=dir('C:\folder\folder2\Desktop\MainFolder\**/*.png'));
and then filter that structure for the names that I need.
But I woudl like to know if it is possible to use reg expressions with a 'dir' function.
Thanks.
Accepted Answer
More Answers (0)
Categories
Find more on File Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!