matlab mkdir gives error

I have a folder named results. I want to create a folder with name datetime in it. I use mkdir but I get error.
t = datetime('now');
folder = ['../results/', datestr(t)];
mkdir(folder);
Error using mkdir The filename, directory name, or volume label syntax is incorrect.

Réponses (3)

Walter Roberson
Walter Roberson le 14 Juil 2017

1 vote

The colon separating the hours and minutes is a reserved character in NTFS filesystems.

1 commentaire

t = datestr(now, 'dd-mmm-yyyy HH-MM-SS');
folder = fullfile('C:\Users\H\Documents\MATLAB\EntropyRateSuperpixel-master\results, t);
mkdir(folder);

Connectez-vous pour commenter.

Image Analyst
Image Analyst le 14 Juil 2017

0 votes

Look at this:
>> datestr(now)
ans =
'13-Jul-2017 23:16:35'
You see those colons in there? The operating system uses those after drive letters, which doesn't make sense for that string. You can use strrep() to replace the colons with something else.
folder = strrep(folder, ':', '_');
Or just delete them,
folder = strrep(folder, ':', '');
or extract out the date only and not the time.
folder = folder(1:11);
RuiQi
RuiQi le 14 Juil 2017

0 votes

The colons were giving an issue. This worked.
t = datetime('now');
t = datestr(t);
t = strrep(t,':','-')
folder = ['C:\Users\H\Documents\MATLAB\EntropyRateSuperpixel-master\results\', t];
mkdir(folder);

Catégories

En savoir plus sur Programming dans Centre d'aide et File Exchange

Tags

Question posée :

le 14 Juil 2017

Commenté :

le 15 Juil 2017

Community Treasure Hunt

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

Start Hunting!

Translated by