Effacer les filtres
Effacer les filtres

Create a subfolder with datetime as its name using mkdir

38 vues (au cours des 30 derniers jours)
Moritz Pohl
Moritz Pohl le 27 Fév 2018
Modifié(e) : NISARGA G K le 8 Mar 2018
Hello folks,
I currently try to create a subfolder in my 'Results' folder which shall be named after the time and date the program was used. So far, this is what I have:
currDate = strrep(datestr(datetime), ' ', '_');
mkdir Results currDate
The problem is that mkdir does not recognize currDate as a char vector. So the created folder is named 'currDate' and not '27-Feb-2018_...'. Can anyone help me out?
Cheers

Réponses (1)

NISARGA G K
NISARGA G K le 8 Mar 2018
Modifié(e) : NISARGA G K le 8 Mar 2018
Hi Moritz
I understand that, you want to create a subfolder with the time and date the program was used as name of the subfolder. 1)Colon is a reserved character and cannot be used in naming the folder. 2)Use function syntax than command syntax while passing variable to 'mkdir'. The following link would help you in understanding better:
https://www.mathworks.com/help/matlab/matlab_prog/command-vs-function-syntax.html
The below code snippet would serve the purpose:
currDate = strrep(datestr(datetime), ':', '_');
mkdir('Results',currDate)

Catégories

En savoir plus sur Entering Commands dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by