matlab.cod​etools.req​uiredFiles​AndProduct​s error for unsupported filenames

37 views (last 30 days)
I get the following error while trying to build a dependency list for some files I need to share with colleagues. I am using a modified version of Daniel Frisch's code ( https://www.mathworks.com/matlabcentral/fileexchange/82768-copy_dependencies ).
From the error message, MATLAB seems to be unable to resolve the filepath for one of the files in the MPT toolbox. I only really care for the code I wrote and as the expectation is that my colleagues also have the same toolboxes installed. Using the 'toponly' flag, I do not get the same error but then I don't get all the files as well. I'd try using the dependency analyser but it runs too slow and includes all files from every toolbox remotely related to my files which I don't exactly need.
Is there any way to fix this?
The code I am executing is basically
name = fileparts(start_mfile);
destination = sprintf('%s-dependencies-%s', name, datestr(now,'yyyymmdd-HHMMSS'));
% Find dependent files
fprintf('Looking for dependent files... ')
flist = matlab.codetools.requiredFilesAndProducts(start_mfile);%,'toponly');
% Create target dir if not exists
if exist(destination,'dir')~=7
mkdir(destination)
end
% Find the individual code files
for iFile = flist
[path,~,~] = fileparts(iFile);
% Explore 2 levels deeper
for i = 1:2
if strcmp(pwd,path)
sublist = matlab.codetools.requiredFilesAndProducts(iFile);%,'toponly');
flist = [flist sublist];
flist = unique(flist,'stable');
end
end
end

Answers (1)

Kanishk
Kanishk on 14 Nov 2024 at 7:15
Edited: Kanishk on 14 Nov 2024 at 7:46
Dear @Elikplim,
It seems you are encountering an issue with “matlab.codetools.requiredFilesAndProducts” due to invalid MATLAB file names that start with "._". These files are typically created by macOS when files are transferred to non-Mac systems or storage formats, Known as AppleDouble files, they store metadata and resource fork information used by macOS.
These “._” files are generally safe to delete, especially if you do not require the macOS-specific metadata or are not planning to transfer the files back to a macOS system. Removing them should resolve the error you are experiencing.
To delete these files, you can use this MATLAB script.
% Define the directory to search in
targetDirectory = 'pathtodirectory/mpt/tbxmanager';
% Get the list of all files starting with ._ in the target directory and subdirectories
filesToDelete = dir(fullfile(targetDirectory, '**', '._*'));
for k = 1:length(filesToDelete)
filePath = fullfile(filesToDelete(k).folder, filesToDelete(k).name);
fprintf('Deleting: %s\n', filePath);
delete(filePath);
end
disp('All ._ files have been deleted.');
Using “matlab.codetools.requiredFilesAndProducts” after deleting these files will not present the error.
To learn more about valid MATLAB file names, please go through this following official MATLAB documentation.
Hope this helps!
Thanks
  3 Comments
Elikplim
Elikplim on 18 Nov 2024 at 16:52
My apologies for not getting back to this sooner. I'm a bit hesitant to delete those files because they came packaged with the toolbox and it is a dependency for a number of other projects and toolboxes I use fairly regularly.
I will try to get access to a separate installation and see if I can get away with deleting the files you suggest before I do this on my computer. Thank you for your responses.

Sign in to comment.

Categories

Find more on File Operations in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!