How to delete empty files/spreadsheets in a directory ?
古いコメントを表示
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 件のコメント
data = {};
writecell(data, 'test.xlsx');
!ls -l test.xlsx
If I understand correctly, you are indicating that the files have no visible content, but still take up about 10 kb of space.
If so then that would suggest that they might have template or macro material written into them, or might have additional sheets.
How do you want to decide whether a particular spreedsheet is empty enough for your purposes?
Ivan Mich
2021 年 3 月 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?
採用された回答
その他の回答 (1 件)
Fangjun Jiang
2021 年 3 月 4 日
0 投票
- 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
Ivan Mich
2021 年 3 月 5 日
カテゴリ
ヘルプ センター および File Exchange で Variables についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!