Working from home on zürich DSP.

This commit is contained in:
silas (home)
2025-03-10 08:56:17 +01:00
parent affdb4ad6f
commit bc86fa8d98
22 changed files with 459 additions and 137 deletions

View File

@@ -0,0 +1,40 @@
function fileName = findFileByCode(folderPath, code)
% FINDFILEBYCODE Searches for a file in a folder structure by a given code.
% fileName = findFileByCode(folderPath, code) searches recursively in
% folderPath for a file containing 'code' in its name and returns the
% full file name if found.
%
% Inputs:
% folderPath - The root directory to search in
% code - The unique code to search for in file names
%
% Output:
% fileName - The full file name if found, empty if not found
% Initialize output
fileName = '';
% Get list of all files and folders in the folderPath
files = dir(folderPath);
% Iterate through the list
for i = 1:length(files)
% Skip '.' and '..'
if files(i).isdir
if ~startsWith(files(i).name, '.') % Avoid hidden folders
% Recursive search in subdirectories
subFolder = fullfile(folderPath, files(i).name);
fileName = findFileByCode(subFolder, code);
if ~isempty(fileName)
return; % Stop searching if found
end
end
else
% Check if the file name contains the code
if contains(files(i).name, code)
fileName = fullfile(folderPath, files(i).name);
return;
end
end
end
end