using dir() to get timestamp of file with ms precision

조회 수: 7 (최근 30일)
supernoob
supernoob 2018년 10월 2일
답변: supernoob 2018년 10월 4일
Hi there,
I am looking to extract the timestamp (specifically, the "modification date") of some files in a folder. If I use dir(), then I can get the modification date in either datetime or datenum format. However, both of these give the timestamp to second precision, but I know the actual timestamp has millisecond precision. I want that millisecond precision. Is there any way to get the timestamp with millisecond precision using dir()? If not, how can I do this?
Thanks in advance!

채택된 답변

supernoob
supernoob 2018년 10월 4일
As Walter Roberson mentioned, this is impossible with dir(). One could use Jan's solution though that was not appropriate in this case. I ended up using shell.

추가 답변 (1개)

Jan
Jan 2018년 10월 2일
Under Windows you can use the C-Mex functions FEX: Filetime
  댓글 수: 7
Jan
Jan 2018년 10월 4일
편집: Jan 2018년 10월 4일
@supernoob: The function GetFileTime can reply the time in the native format as stored in the file system as UINT64 counted in steps of 100ns. Then you can convert this how ever you like it.
The C-Mex function uses the Windows library function FileTimeToSystemTime, which rounds to milliseconds.
supernoob
supernoob 2018년 10월 4일
@Jan, thanks that's good to know. It seems likely the rounding error was from the FileTimeToSystemTime.

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

카테고리

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