Something like this
d = uigetdir(pwd, 'Select a folder');
files = dir(fullfile(d, '*.s2p'));
for i = 1:numel(files)
original_name = fullfile(files(i).folder, files(i).name);
new_name = strrep(original_name, ' ', '_');
movefile(original_name, new_name)
end