How to delete empty files/spreadsheets in a directory ?
조회 수: 9 (최근 30일)
이전 댓글 표시
Hello,
I have a directory with milions of .xlsx files. The point is that I want to remove empty files. Is there a way to do it using a command in matlab? Instead of the fact that these files are empty, they have 10kb.
Could you please help me?
댓글 수: 4
Walter Roberson
2021년 3월 4일
To clarify:
Files that have only one line of data should be deleted, but files that have more than one line of data should not be deleted?
채택된 답변
Ivan Mich
2021년 3월 5일
편집: Ivan Mich
2021년 3월 7일
추가 답변 (1개)
Fangjun Jiang
2021년 3월 4일
- run [STATUS,SHEETS] = xlsfinfo(FILENAME). Most likely, it will tell you there is only one sheet
- run [NUM,TXT,RAW]=xlsread(FILENAME). Most likely, isempty(NUM) and isempty(TXT) are both true
- delete(FILENAME)
댓글 수: 2
Walter Roberson
2021년 3월 4일
Alternative to the second step:
C = readcell(FILENAME);
isempty(C)
For example,
[STATUS, SHEETS] = xlsfinfo(FILENAME);
if length(SHEETS) > 1; next; end %assume multiple sheet files are special
C = readcell(FILENAME, 'sheet', SHEETS{1});
if isempty(C); delete(FILENAME); end
참고 항목
카테고리
Help Center 및 File Exchange에서 Entering Commands에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!