Move files to a new folder for every model run

1 view (last 30 days)
Shaibal Ahmed
Shaibal Ahmed on 21 Apr 2017
Answered: Rik on 21 Apr 2017
I'm looking for a solution where after running the executable I can store some newly created files for example, newfile_1.txt, newfile_2.txt to a new folder (Run_1, Run_2...) for every run. I can only create one folder which overwrites the moved files after every run.
% set working directory
cd('E:\Tutorial\SimFolder\');
runpath = 'E:\Tutorial\SimFolder\';
myDir = 'E:\Tutorial\New_Files\'; %gets directory of files to be copied
myFiles = dir(fullfile(myDir,'*.txt')); %gets all txt files in struct e.g. file_1.txt, file_2.txt...
for k = 1:length(myFiles)
baseFileName = myFiles(k).name;
fullFileName = fullfile(myDir, baseFileName);
copyfile(fullFileName,[runpath 'file.txt']); %copy & rename file for every run
system('program.exe'); %run executable
movefile([runpath 'newfile_1.txt'],'E:\Tutorial\Results\Run_1'); %this part needs to change
end

Answers (1)

Rik
Rik on 21 Apr 2017
You mean something like this?
movefile([runpath sprintf('newfile_%d.txt',run_number)],sprintf('E:\\Tutorial\\Results\\Run_%d',run_number));

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!