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

10 ビュー (過去 30 日間)
Daniel Boateng
Daniel Boateng 2019 年 3 月 12 日
編集済み: Adam Danz 2019 年 3 月 12 日
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 Center および File ExchangeOil, Gas & Petrochemical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by