ojasony
ojasony

Reputation: 49

Struct contents reference from a non-struct array object

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

Upvotes: 0

Views: 891

Answers (1)

Dominic D
Dominic D

Reputation: 1808

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

Upvotes: 1

Related Questions