Move files to a new folder for every model run

2 visualizzazioni (ultimi 30 giorni)
Shaibal Ahmed
Shaibal Ahmed il 21 Apr 2017
Risposto: Rik il 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

Risposte (1)

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

Categorie

Scopri di più su Startup and Shutdown in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by