删除一个文件:delete(filename)
删除一类文件:delete(‘*.后缀’)
删除文件夹及文件夹下的文件:rmdir(文件夹名字,‘s)
%% 重命名文件
foldname ={'Baseline','control','followup'};
path = 'F:\Depression_byPLM';
for i = 2:2%3
fold_path = [path filesep foldname{i} filesep];
sub_dir = dir(fold_path);
sub_dir = sub_dir(3:end);
for j = 1:length(sub_dir)
files = dir([fold_path,sub_dir(j).name,filesep,'dti\','dti*.nii.gz']);
n = length(files);
display(sub_dir(j).name)
for ifile = 1:n
oldname = files(ifile).name;
% sub_add = sub_dir(j).name(1:10);
sub_add = sub_dir(j).name;
newname = [sub_add oldname(4:end)];
cd([fold_path,sub_dir(j).name,filesep,'dti\'])
eval(['!rename' 32 oldname 32 newname]);
end
end
end
%% 重命名文件夹
arrayfun(@(i)(dos(sprintf('ren dti native_space') )),[1]);