MATLAB Answers

How do I save multiple .txt files from different folders to one new folder?

6 ビュー (過去 30 日間)
Emily Frith
Emily Frith 2021 年 3 月 9 日
編集済み: Rena Berman 2021 年 5 月 6 日 20:18
I have saved txt files to a directory, but this just gives me the names. I cannot then access the files in the directory and compile them in one place.
  2 件のコメント
Rena Berman
Rena Berman 2021 年 5 月 6 日 20:13

(Answers Dev) Restored edit

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

回答 (1 件)

Walter Roberson
Walter Roberson 2021 年 3 月 9 日
filenames = fullfile({fileList.folder}, {filelist.name});
copyfile(filenames, outputPath);
This assumes that the source files all have different base names (the part without the folder). If the names might be the same, then you need to decide what the output file names are to be in cases where there is a clash.
  7 件のコメント
Walter Roberson
Walter Roberson 2021 年 3 月 9 日
Did you check to see whether it exists already and mkdir it if not?
if ~isfolder(outputPath); mkdir(outputPath); end
for R2017a and earlier use isdir() instead of isfolder()

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

Community Treasure Hunt

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

Start Hunting!

Translated by