HOW TO CREATE A FOLDER WITH DIFFERENT NAMES AND A SUBFOLDER FOR EACH FOLDER

15 次查看(过去 30 天)
I want to create different folders with name simulation_Data1,simulation_Data2,simulation_Data3 and so on and each folder I want to have a subfolder called real_Data in every simulation_Data Folder. Please how do i go about this.
maximum_Folder = 10;
ROOT_FOLDER = 'Simulation_Data';
for n = 1:MAX_FOLDER_NUMBER
folder_name = [ROOT_FOLDER,sprintf('%d',n)];
mkdir([Name_Project_folder \'folder_name'\'Real_Data'])
if not(exist(folder_name,'dir'))
mkdir(folder_name)
end
end

采纳的回答

Adam Danz
Adam Danz 2019-3-12
编辑:Adam Danz 2019-3-12
At the top, define the parent directory (the directory where your simulation data folders will go). Then set the number of simulation data folders to be created. The code will loop through each new folder and create the simulation_datax folder and the real_data subfolder. If the simulation data folder already exists, the iteration will be skipped.
parentdir = 'C:\Users\hristobotev\Documents\MATLAB\mydata'; %parent directory
maximum_Folder = 10; %number of simulation_Data folders to create
ROOT_FOLDER = 'simulation_Data'; %base name for folder 1
f2name = 'real_Data'; %base name for folder 2
for n = 1:maximum_Folder
newfolder = fullfile(parentdir, sprintf('%s%d', ROOT_FOLDER, n));
status = mkdir(newfolder);
if status
mkdir(fullfile(newfolder, f2name));
end
end

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Oil, Gas & Petrochemical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by