folderPath = "/Volumes/NT-Labor/2024/sioe/High Speed Messungen Oktober/"; % Get list of all files in the folder and subfolders fileList = dir(fullfile(folderPath, '**', '*')); % Loop through each file for i = 1:length(fileList) % Get the file name and path oldFileName = fileList(i).name; oldFilePath = fullfile(fileList(i).folder, oldFileName); % Skip if it’s a directory or hidden file if fileList(i).isdir || startsWith(oldFileName, '.') continue; end ismat = strfind(oldFileName, '.mat'); if ismat continue; else % Find position of last dot (for file extension) dotIndex = strfind(oldFileName, '.'); % Only proceed if there is more than one dot in the file name if ~isempty(dotIndex) % Replace all dots in the "base name" with underscores sanitizedBaseName = strrep(oldFileName, '.', '_'); % Create the new file name with the corrected extension newFileName = [sanitizedBaseName, '.mat']; % Full path of the new file newFilePath = fullfile(fileList(i).folder, newFileName); % Rename the file movefile(oldFilePath, newFilePath); fprintf('Renamed: %s -> %s\n', oldFilePath, newFilePath); end end end