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

3 vues (au cours des 30 derniers jours)
Emily Frith
Emily Frith le 9 Mar 2021
Modifié(e) : Rena Berman le 6 Mai 2021
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 commentaires
Stephen23
Stephen23 le 9 Mar 2021
Modifié(e) : Stephen23 le 9 Mar 2021
@Emily Frith: your question is confusing.
For example, the title is "How do I save multiple .txt files from different folders to one new folder?", but then you explained that "I have saved txt files to a directory...". So which of these is correct: are the files in multiple folders (like your title states) or in one folder (as per your explanation)?
"I have saved txt files to a directory, but this just gives me the names"
Saving data in a file does not "give" names. If you "got" the names, then this is due to some other action or process.
"I cannot then access the files in the directory..."
Why not? What have you tried so far?
Rena Berman
Rena Berman le 6 Mai 2021

(Answers Dev) Restored edit

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
Walter Roberson le 9 Mar 2021
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 commentaires
Emily Frith
Emily Frith le 9 Mar 2021
it is a folder.
outputPath = fullfile(mainFolder, 'motion_covariates');
Walter Roberson
Walter Roberson le 9 Mar 2021
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()

Connectez-vous pour commenter.

Catégories

En savoir plus sur File Operations dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by