I understand that you only want directories ending with specific extensions from the list. Here's the updated MATLAB script to accomplish that:
```matlab
% Define the input directory
inputDirectory = '/path/to/your/directory'; % Change this to your desired directory
% List of file extensions to match
validExtensions = {'.cs', '.tdm', '.rt', '.xm', '.tdms_inde', '.tx', '.mp', '.ch'};
% Get a list of all items (files and directories) in the input directory
allItems = dir(inputDirectory);
% Initialize an empty cell array to store matching directories
matchingDirectories = {};
% Iterate through each item in the directory
for i = 1:numel(allItems)
currentItem = allItems(i);
% Check if the item is a directory
if currentItem.isdir
% Extract the directory name
dirName = currentItem.name;
% Check if the directory name ends with one of the specified extensions
for j = 1:numel(validExtensions)
currentExtension = validExtensions{j};
if endsWith(dirName, currentExtension)
matchingDirectories = [matchingDirectories, {dirName}];
break; % No need to check other extensions for this directory
end
end
end
end
% Display the list of matching directories
fprintf('Matching directories in %s:\n', inputDirectory);
for i = 1:numel(matchingDirectories)
fprintf('%s\n', fullfile(inputDirectory, matchingDirectories{i}));
% Get the source and destination paths
sourceDir = fullfile(inputDirectory, matchingDirectories{i});
destinationDir = inputDirectory;
% Copy the contents of the source directory to the destination directory
copyfile(sourceDir, destinationDir);
% Delete the source directory
rmdir(sourceDir, 's');
end
fprintf('All matching directories have been processed.\n');
```
This script will list and process only directories in the input directory that end with any of the specified extensions in the `validExtensions` list.