matlab.codetools.requiredFilesAndProducts error for unsupported filenames
37 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
1 Kommentar
Walter Roberson
am 14 Nov. 2024 um 3:25
I would rename the ._buildCost.m to something else, such as ._buildCost.mold
Antworten (1)
Kanishk
am 14 Nov. 2024 um 7:15
Bearbeitet: Kanishk
am 14 Nov. 2024 um 7:46
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 Kommentare
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!