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

9 views (last 30 days)
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

Accepted Answer

Adam Danz
Adam Danz on 12 Mar 2019
Edited: Adam Danz on 12 Mar 2019
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

More Answers (0)

Categories

Find more on Oil, Gas & Petrochemical 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!