How to delete files ending with odd number?
Show older comments
Hi,
I would like to delete each files having its filename ending by an odd number. Example: file0 file1 file2 file3 file4 After: file0 file2 file4
Thank you for your help :)
Accepted Answer
More Answers (1)
Morgane Flament
on 13 Aug 2018
0 votes
4 Comments
Simon Henin
on 13 Aug 2018
Sure, instead of checking if mod(fileno, 2)== 1, you could look at the remainder:
if rem(fileno, 10) == 1 | rem(fileno, 10) == 2,
% then delete the file
end
Morgane Flament
on 13 Aug 2018
Edited: Morgane Flament
on 13 Aug 2018
Paolo
on 13 Aug 2018
@Morgane,
If you wish to delete only files ending with 2,3,4 or 5, change the character set in the regex:
regexp(files(i).name, '[2345]$', 'match')
Morgane Flament
on 13 Aug 2018
Categories
Find more on Standard File Formats 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!