sorting folder based on what type of files it contains

1 次查看(过去 30 天)
I want to sort folders based on what it contains. so i have folders with names 0008,0009, etc. they each have contents inside, but some does not have a .dcm file some does not have a bmp file ( inside subfolders ) . i want to sort this folders and put it into another parent folder no dicom and no bmp. i have attached a picture of how the folders i want to move look. I made the code below but it moved all the files to the no bmp folder instead
nufolderpath = '/Users/sesiliamaidelin/Downloads/summer project/Copy_of_nufolder';
nu_filesAndFolders = dir([nufolderpath '/**']);% Get all subfolder and files names
nu_folders = dir([nufolderpath])
nu_allfolders = {nu_folders.name}
nu_alllist={nu_filesAndFolders.name} % Convert to cell
for ll= 1:numel(nu_allfolders) %ok
currfolder = nu_allfolders{ll};
nupath = fullfile( nufolderpath, currfolder)
if isempty(dir(fullfile(nupath,'*.dcm')))
copyfile(fullfile(nufolderpath,currfolder), fullfile(nufolderpath, 'no dcm'))
end
end

采纳的回答

Shravan Kumar Vankaramoni
Hi,
Below code demostrates sorting folders based on certain files and move them to another folder.
fileList = dir('*.bmp'); % It lists the files with .bmp extension
x = size(fileList); %Find the size of output
if(x(1) == 0) % if no .bmp files are present, move folder to nobmp folder
movefile source destination; %replace source and destination with respective paths
end
Refer the below link for more information:

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 File Operations 的更多信息

产品


版本

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by