sorting folder based on what type of files it contains
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
sesilia maidelin
el 22 de Jul. de 2021
Comentada: sesilia maidelin
el 2 de Ag. de 2021
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
0 comentarios
Respuesta aceptada
Shravan Kumar Vankaramoni
el 29 de Jul. de 2021
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:
Más respuestas (0)
Ver también
Categorías
Más información sobre File Operations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!