フィルターのクリア

outputfile name using the inputfile name

14 ビュー (過去 30 日間)
WENDILYN GUIDOTTI
WENDILYN GUIDOTTI 2022 年 10 月 18 日
コメント済み: WENDILYN GUIDOTTI 2022 年 10 月 18 日
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);

採用された回答

Image Analyst
Image Analyst 2022 年 10 月 18 日
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
  1 件のコメント
WENDILYN GUIDOTTI
WENDILYN GUIDOTTI 2022 年 10 月 18 日
This worked so great, I appreciate you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Import from MATLAB についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by