MATLAB Answers


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

Asked by Shuster
on 4 Nov 2012

i have a bunch ('n') of files named in the following way


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

  1 Comment

on 4 Nov 2012

136b? What does that mean? Do you want a number or a string?



No products are associated with this question.

2 Answers

Answer by Jan Simon
on 4 Nov 2012
 Accepted answer

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*');


Answer by 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


Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!