sorting folder based on what type of files it contains
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
sesilia maidelin
am 22 Jul. 2021
Kommentiert: sesilia maidelin
am 2 Aug. 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 Kommentare
Akzeptierte Antwort
Shravan Kumar Vankaramoni
am 29 Jul. 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:
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu File Operations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!