Copyfile doesn't preserve timestamp

조회 수: 6 (최근 30일)
Vincenzo
Vincenzo 2020년 7월 19일
댓글: Walter Roberson 2020년 7월 21일
[status, msg, msgID] = copyfile(filePath1, filePath2);
This line copies a file from a local directory into a USB drive, but the timestamp is not preserved, and the current time is used instead.
Why does this happen if the documentation says the opposite?
MATLAB R2019b, macOS High Sierra 10.13.6
  댓글 수: 4
Stephen23
Stephen23 2020년 7월 20일
Vincenzo'S "Answer" moved here:
I also observed that this behaviour is somewhat file-dependent.
On one file I get the same modified date as the original copy, on other ones (a .dmg file, a .png file) I get the current time as the modified date.
Strangely, the creation date is set for both at an arbitrary date, to which I see no link with the original copies.
Stephen23
Stephen23 2020년 7월 20일
Vincenzo's "Answer" moved here:
Let me disagree here. The documentation doesn't specify an OS-dependent compatibility, so if it's an OS-dependent issue, it means it's an OS-dependent bug in TMW-specific code. It would be useful to compare results to analyze different behaviours and possibly raise a bug fix request to The Mathworks.

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

답변 (1개)

Image Analyst
Image Analyst 2020년 7월 20일
Windows has 3 dates: modified date, created date, and accessed date. Maybe macOS is the same. For Windows 10, the modified date is the same as it was. The Created date and the Accessed date of the new file are the current time that copyfile() was executed. The documentation only says "After a successful copyfile operation, the timestamp for the new file is the same as the timestamp for source." I agree this is ambiguous when the operating system maintains 3 dates for the files. It could be more explicit on what "timestamp" means especially when only one of the timestamps is the same and two will be different. You could click the single star at the bottom of the documentation and then put in your suggestion (like I just did). I know people do read those suggestions.
MATLAB also does not seem to have a touch function so perhaps you can use system() to run such a command after you run copyfile(), if your operating system has such a touch function.
  댓글 수: 7
dpb
dpb 2020년 7월 21일
If you can create a reproducible test case that illustrates a problem, submit a formal bug report to TMW. Answers is NOT official support. See "Contact Us" (the old-style telephone receiver) icon at top of page or email support@mathworks.com
Walter Roberson
Walter Roberson 2020년 7월 21일
For folder synchronization you should consider system() of rsync

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

카테고리

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

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by