0

I want to create a loop to delete file within specific file size and I have these problems.

selpath = uigetdir(files) 
for ii = 1:length(files)
    if files(ii).bytes<500000   % 500kb
        delete(fullfile(files(ii).folder, files(ii).name))
    end
end

and I always got this message

>> cobayginibro

selpath =

    'D:\Proyekan Tes'

Struct contents reference from a non-struct array object.

Error in cobayginibro (line 3)
    if files(ii).bytes<500000   % 500kb

Any idea how to solve this? Also I want to fprint how many files i've deleted Thanks before

2
  • What is files and how is it set? Commented Feb 17, 2020 at 2:07
  • ah sorry, I want the files to be choosen from the selpath Commented Feb 17, 2020 at 2:49

1 Answer 1

1

You just need to set files after getting selpath.

selpath = uigetdir() 
files = dir(selpath)
for ii = 1:length(files)
    if ~files(ii).isdir && files(ii).bytes<500000   % 500kb
        delete(fullfile(files(ii).folder, files(ii).name))
    end
end
Sign up to request clarification or add additional context in comments.

1 Comment

I considered adding a check for files(ii).isdir, but directories have a size of 0 bytes anyway

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.