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

조회 수: 4 (최근 30일)
Shuster
Shuster 2012년 11월 4일
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
  댓글 수: 1
José-Luis
José-Luis 2012년 11월 4일
편집: José-Luis 2012년 11월 4일
136b? What does that mean? Do you want a number or a string?

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2012년 11월 4일
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*');

추가 답변 (1개)

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

카테고리

Help CenterFile Exchange에서 Workspace Variables and MAT-Files에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by