필터 지우기
필터 지우기

problem with dir function in R2014A

조회 수: 2 (최근 30일)
Eyal weinberger
Eyal weinberger 2014년 12월 2일
답변: michael scheinfeild 2014년 12월 18일
after updating to R2014A, when I use the dir command i get a message: Caught "std::exception" Exception message is: Cannot convert dates prior to Jan 1, 1970
what does it means and how do I solve the problem?

답변 (2개)

Guillaume
Guillaume 2014년 12월 2일
There's a bug with dir, imfinfo and probably some other functions when they encounter a file with a modification date outside of a certain range.
In your case, it looks like you have a file with a modification date older than 1970. It's a perfectly valid file and matlab shouldn't choke on it but it does. I wasn't aware it occurred as well in 2014A, I thought it only appeared in 2014B because of their new datetime type. I've reported the bug to Mathworks. Whether it'll be fix anytime soon is unknown. Probably not, it's not even appeared in their bug database.
You have several workaround:
  1. Find the offending file(s) with windows explorer and edit it to change its modification time to now
  2. Use system(dir) (windows) system(ls) (unix) and parse the output yourself
  3. Use .Net (windows) System.IO.Directory methods, e.g. to get all files in a directory:
files = cell(System.IO.Directory.GetFiles(foldername));
See also this answer
  댓글 수: 2
Guillaume
Guillaume 2014년 12월 2일
편집: Guillaume 2014년 12월 2일
However, I would note that the limitation of jan 1, 1970 is not unique to matlab. Some of the times on Windows and Unix are stored as the numbers of second ellapsed since Jan 1, 1970 and thus can't be any earlier. Even Windows Explorer doesn't cope well with dates before 1970: it doesn't display the date in the details column.
This is not the case for file modification time on Windows though. The reference is Jan 1, 1601.
Guillaume
Guillaume 2014년 12월 2일
Also, in R2014b, I can't get dir to fail with modification dates before 1970, so this particular error may have been fixed in the latest version.

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


michael scheinfeild
michael scheinfeild 2014년 12월 18일
so there is no quick solution , what i did is rename all files to a(1).jpg , a(2).jpg
ant then run in loop where name is name=strcat ('a(',num2str(ind),').jpg')

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by