Move files to a new folder for every model run

5 vues (au cours des 30 derniers jours)
Shaibal Ahmed
Shaibal Ahmed le 21 Avr 2017
Réponse apportée : Rik le 21 Avr 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

Réponses (1)

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

Catégories

En savoir plus sur Startup and Shutdown 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