Skip to content

Commit

Permalink
cleanup: conditional statement to delete files
Browse files Browse the repository at this point in the history
  • Loading branch information
CPernet committed Nov 28, 2023
1 parent dbf5861 commit cc103a8
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions bids/spmup_BIDS_preprocess.m
Original file line number Diff line number Diff line change
Expand Up @@ -1745,7 +1745,11 @@
prefixList = {'bmask*', 'rbmask*'};
for nprefix = 1:numel(prefixList)
tmp = dir(fullfile(anatpath,prefixList{nprefix}));
toDelete = [toDelete; tmp]; % add to list
if ~isempty(tmp)
if exist(tmp(1).name,'file')
toDelete = [toDelete; tmp]; % add to list
end
end
end

% delete files
Expand All @@ -1764,19 +1768,37 @@
toDelete = struct('name','','folder','','date','','bytes','','isdir','','datenum','');

tmp = dir(fullfile(filepath,[filename(1:end-5) '_skip-' num2str(options.removeNvol) '_bold*'])); % volume edited
toDelete = [toDelete; tmp]; % add to list
if ~isempty(tmp)
if exist(tmp(1).name,'file')
toDelete = [toDelete; tmp]; % add to list
end
end

tmp = dir(fullfile(filepath,[filename(1:end-5) '*_rec-despiked_bold' ext])); % despiked
toDelete = [toDelete; tmp]; % add to list
if ~isempty(tmp)
if exist(tmp(1).name,'file')
toDelete = [toDelete; tmp]; % add to list
end
end

% list of prefixes to delete
prefixList = {'st_*', 'rst_*', 'ur*', 'usub*', 'rst_*', 'ur*', 'usub*', 'wusub*', 'ust*', 'wst*', 'wur*', 'wfmag*', 'mean*', 'wmean*'};
for nprefix = 1:numel(prefixList)
tmp = dir(fullfile(filepath,[prefixList{nprefix} ext]));
toDelete = [toDelete; tmp]; % add to list
if ~isempty(tmp)
if exist(tmp(1).name,'file')
toDelete = [toDelete; tmp]; % add to list
end
end
end

tmp = dir(fullfile(filepath,'st_*.mat'));
toDelete = [toDelete; tmp]; % add to list

if ~isempty(tmp)
if exist(tmp(1).name,'file')
toDelete = [toDelete; tmp]; % add to list
end
end

% delete files
if numel(toDelete)>1
arrayfun(@(x) delete(fullfile(x.folder, x.name)), toDelete(2:end), 'UniformOutput', false);
Expand Down

0 comments on commit cc103a8

Please sign in to comment.