Files missing from a folder
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
How skip the missing files from a sequence of 2041 text files by code.
example shown in picture.
Note: There are many missing files in a folder![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/364147/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/364147/image.jpeg)
0 commentaires
Réponses (1)
Walter Roberson
le 22 Sep 2020
for K = 1 : 2041
thisfile = sprintf('%d.txt', K);
if ~exist(thisfile, 'file'); continue; end
%file exists, process it
end
Or use dir() to find what does exist.
Note that if you use dir() and the file names do not have leading zeros for the one and two digit file names, then the order dir() returns will typically not be numeric. dir() does not define the order it returns files in, but typically the order is sorted by character value from left to right, so '1.txt' then '10.txt' because of how '0' sorts relative to '.'
0 commentaires
Voir également
Catégories
En savoir plus sur File Operations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!