outputfile name using the inputfile name
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
WENDILYN GUIDOTTI
el 18 de Oct. de 2022
Comentada: WENDILYN GUIDOTTI
el 18 de Oct. de 2022
I am trying to have the input file name pulled into the output file name in an excel format, and I added a letter so they can exist in the same folder. However, it is taking the file names with similar starting numbers and combining them even thought the rest of the file name is different. So if there are three files that start with 2022 I only get one excel file 2022 with the last file name in the chain. What am I missing?
EX:
TKL = rmfield(tkl, 'field_');
TK = structure2table(TKL);
cd = 'C: folderlocation';
inputfile = filename(kk).name;
[~,fname] = fileparts(inputfile);
outputfile = sprintf('%s_D.xlsx',fname);
writetable(TK,outputfile,'sheet',1);
0 comentarios
Respuesta aceptada
Image Analyst
el 18 de Oct. de 2022
You need to have a loop over all the files
TKL = rmfield(tkl, 'field_');
TK = structure2table(TKL);
folder = 'C:\folderlocation';
filePattern = fullfile(folder, '/2022*.xlsx');
fileList = dir(filePattern);
numFiles = numel(fileList);
fprintf('Found %d files matching the pattern "%s".\n', numFiles, filePattern)
% Copy TK into the same number of new files having the same name
% but with a "_D" suffix.
for k = 1 : numFiles
fullInputFileName = fullfile(fileList(k).folder, fileList(k).name);
% Prepare the output file name.
[~, baseFileNameNoExt, ext] = fileparts(fullInputFileName);
baseOutputFileName = sprintf('%s_D.xlsx', baseFileNameNoExt);
fullOutputFileName = fullfile(folder, baseOutputFileName);
writetable(TK, fullOutputFileName, 'Sheet', 1);
end
Más respuestas (0)
Ver también
Categorías
Más información sobre Startup and Shutdown en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!