MATLAB Answers

Delete files with specific sizes

6 views (last 30 days)
Oktavian Jason
Oktavian Jason on 14 Feb 2020
Commented: Bhaskar R on 15 Feb 2020
Hello everyone,
I want to ask a question.
I have a directory of flight data files and I want to delete some files that have less size than, for example 500 kb.
Is there any way to do it in loop?
Thanks

  0 Comments

Sign in to comment.

Accepted Answer

Bhaskar R
Bhaskar R on 14 Feb 2020
Get the directory files
files = dir('your directory');
Apply loop and delete with your condition
for ii = 1:length(files)
if files(ii).bytes<500000 % 500kb
delete(fullfile(files(ii).folder, files(ii).name)
end
end

  5 Comments

Show 2 older comments
Oktavian Jason
Oktavian Jason on 14 Feb 2020
thank you very much! will try this
Oktavian Jason
Oktavian Jason on 14 Feb 2020
actually i'm a bit confused how to use these. (i'm new to matlab).
can you please give me the example?
let's say my folder is "Project" in D drive, and the folder has about 600 files.
Bhaskar R
Bhaskar R on 15 Feb 2020
You can learn/refer MATLAB fundamentals to apply solution to your problem. MATLAB provides very rich documentation clearly.

Sign in to comment.

More Answers (0)

Sign in to answer this question.