How to put a struct files into a new folder

9 views (last 30 days)
Hi guys,
After i use the following code to find files i want, how to put those files into the new folder? Thank you.
This code will give me the info of files in a struct such as name, path, size etc.
files = dir('D:\Data\**\*.mat')
Coco on 22 Jul 2019
Hi Walter
Sorry for the late reply.
Each csv file's name is unique and the cell# prefix matches the folder name.
For example: in folder 'MDA cell1', all of csv file is 'cell1_Area','cell1_distance'.... There is no cell2_* in folder 'MDA cell1'.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 22 Jul 2019
destdir = 'D:\Data\MDA\MDA Matlab\Area';
files = dir('D:\Data\MDA\MDA*\cell*_Area.csv');
fullnames = fullfile({files.folder}, {});
if ~exist(destdir, 'dir')
copyfile(fullnames, destdir); %or movefile() if appropriate
Nagamani Yaadavalli
Nagamani Yaadavalli on 8 Dec 2020
What if the output data has to save in an excel/csv format in a different folder. Here the the output of Analysis1 wants to save in a new excel/csv file in different folder or soeother directory. Please help me with this code.
% getting the folder directory of files you want to work
myFolder = '/Users/xxxxx/Desktop/xxxxx/Tests/27.11.2020 csv/Total';
% code for determining the file pattern that you have, * represents all the
% files
filePattern = fullfile(myFolder, '*.csv');
% code for addressing all the files
theFiles = dir(filePattern)
for k = 1: length(theFiles)
baseFileName = theFiles(k).name;
fullfilename = fullfile(theFiles(k).folder,baseFileName)
Test= dlmread(fullfilename,',',1,2)
theMeans = mean(Test,1)
Analysis1(:,k) = theMeans'

Sign in to comment.

More Answers (1)

Coco on 22 Jul 2019
i also tried to save the file one by one, then it worked. just i dont know how to save them all automatically. any help? thank you.
f=fullfile('D:\','Data','MDA231','MDA231 Mito cell1_Statistics','MDA231 Mito cell1_Area.csv')
f =
'D:\Data\MDA231\MDA231 Mito cell9_Statistics\MDA231 Mito cell9_Area.csv'
>> copyfile(f, destdir)

Community Treasure Hunt

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

Start Hunting!