How to delete files ending with odd number?
Mostra commenti meno recenti
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 :)
Risposta accettata
Più risposte (1)
Morgane Flament
il 13 Ago 2018
0 voti
4 Commenti
Simon Henin
il 13 Ago 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
il 13 Ago 2018
Modificato: Morgane Flament
il 13 Ago 2018
Paolo
il 13 Ago 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
il 13 Ago 2018
Categorie
Scopri di più su Standard File Formats in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!