- #1
member 428835
Hi PF!
I have a list of files data0.0.csv, data0.1.csv, data0.2.csv,...data0.10.csv... I would like to pad the central number with a zero for single digit cases, so that my files become data0.0.csv, data0.1.csv, data0.2.csv,...data0.10.csv... So far my code looks like this
but then I think I would have to use the movefile function. Overall I am just very stuck. Please help!
I have a list of files data0.0.csv, data0.1.csv, data0.2.csv,...data0.10.csv... I would like to pad the central number with a zero for single digit cases, so that my files become data0.0.csv, data0.1.csv, data0.2.csv,...data0.10.csv... So far my code looks like this
Matlab:
% DEFINE FILE DIRECTORY
path = ('/home/josh/CSV_FILES/');
addpath(path)
% LOAD .csv FILES
% INFO ABOUT FILE CONTENTS
csv_info = dir(path_intfce);
% EXTRACT FILENAMES WITHIN FOLDER
file_names = {csv_info(:).name}';
% FILTER ONLY .csv EXTENSIONS
csv_files = file_names(endsWith(file_names,'.csv'));
% I AM GOOD UP TO HERE: EVERYTHING WORKS
% PAD FILES
for id = 1:length(csv_files)
csv_num(id) = HELP! % SHOULD EXTRACT JUST CENTRAL NUMBER HERE
% If numeric, rename
if length('csv_num') < 2
csv_num(id) = num2str(csv_num(id),'%02.d');
end
end
but then I think I would have to use the movefile function. Overall I am just very stuck. Please help!