read file names of files beyond a specific size into a vector

5 views (last 30 days)
i have a bunch ('n') of files named in the following way
asdfxxxxxx_pqrs.txt
where xxxxxx stands for 6 digit zero padded number
ex : xxxxxx can be any of 000000 000001 000002 000003 . .
Of these files, all of ~136b but rest of not. I need to read the numbers (without zero padding) of those files that are larger than 136b into a vector

Accepted Answer

Jan
Jan on 4 Nov 2012
If "136b" means a file size of 136 Bytes:
list = dir(fullfile(YourPath, 'asdf??????_pqrs.txt')
FileSize = [list.bytes];
FileName = {list(FileSize > 136).name};
Worm = sprintf('%s*', FileName{:});
Number = sscanf(Worm, 'asdf%d_pqrs.txt*');

More Answers (1)

Walter Roberson
Walter Roberson on 4 Nov 2012
One of the fields returned by dir() is the file size.
dirinfo([dirinfo.bytes <= 136]) = []; %removes info for files 136 bytes or less

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!