sorting folder based on what type of files it contains

1 回表示 (過去 30 日間)
sesilia maidelin
sesilia maidelin 2021 年 7 月 22 日
コメント済み: sesilia maidelin 2021 年 8 月 2 日
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
Shravan Kumar Vankaramoni 2021 年 7 月 29 日
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 Center および File ExchangeFile Operations についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by