Hello,
I have the following code below that works just fine for unzipping and deleting files.
files = fullfile(matlabroot, '\toolbox');if ~exist(files, 'dir') files = matlabroot;enduiwait(msgbox('Pick a folder on the next window that will come up.'));selpath = uigetdir(files);if selpath == 0 return;endprojectdir = selpath; dinfo = dir( fullfile( projectdir, '**', '*.zip') ); %find all .zip underneath the projectdir.
%then
for K = 1 : length(dinfo) unzip(fullfile(dinfo(K).folder,dinfo(K).name),selpath);endfiles = dir(projectdir);deletedfiles = 0;for itr = 1:length(files) if files(itr).bytes<500000 && ~files(itr).isdir files.name delete(fullfile(files(itr).folder, files(itr).name)) deletedfiles=deletedfiles+1; endenddeletedfiles
But, after I want to rename the files, so after the unzip loop, I made this changes.
files = fullfile(matlabroot, '\toolbox');if ~exist(files, 'dir') files = matlabroot;enduiwait(msgbox('Pick a folder on the next window that will come up.'));selpath = uigetdir(files);if selpath == 0 return;endprojectdir = selpath; dinfo = dir( fullfile( projectdir, '**', '*.zip') ); %find all .zip underneath the projectdir.%thenfor K = 1 : length(dinfo) unzip(fullfile(dinfo(K).folder,dinfo(K).name),selpath);endfor id = 1:length(files) % Get the file name (minus the extension)
[~, f] = fileparts(files(id).name); % write the rename file
rf = strcat('Flight_10001',ext) ; % rename the file
movefile(files(id).name, rf);endfiles = dir(projectdir);deletedfiles = 0;for itr = 1:length(files) if files(itr).bytes<500000 && ~files(itr).isdir files.name delete(fullfile(files(itr).folder, files(itr).name)) deletedfiles=deletedfiles+1; endenddeletedfiles
and got this following errror
Struct contents reference from a non-struct array object.Error in UnzipnDelete (line 18) [~, f] = fileparts(files(id).name);
Any ideas how to fix this? I just want to rename it to "Flight 10001, Flight 10002, and so on"
Best Answer