matlab mkdir gives error

조회 수: 21 (최근 30일)
RuiQi
RuiQi 2017년 7월 14일
댓글: Walter Roberson 2017년 7월 15일
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.

답변 (3개)

Walter Roberson
Walter Roberson 2017년 7월 14일
The colon separating the hours and minutes is a reserved character in NTFS filesystems.
  댓글 수: 1
Walter Roberson
Walter Roberson 2017년 7월 15일
t = datestr(now, 'dd-mmm-yyyy HH-MM-SS');
folder = fullfile('C:\Users\H\Documents\MATLAB\EntropyRateSuperpixel-master\results, t);
mkdir(folder);

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2017년 7월 14일
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 2017년 7월 14일
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);

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by