Is it possible to obtain the creation date of a directory or file in MATLAB 7.5 (R2007b)?

47 views (last 30 days)
I am trying to obtain the creation date of a directory or a file. I am able to obtain the modification date of a file by using the DIR command. For example:
d = dir('myfile.txt');
moddate = d.date;
I want to know if there is a similar command that returns the creation date.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 14 Jun 2017
The ability to directly obtain the file or directory creation date is not available in MATLAB.
As a workaround, use the operating system interface to obtain the creation date of a file or directory. The DOS command allows one to execute functions from the Windows system shell. DIR then gives the file information stored by the operating system. For example, if your working directory contains the file 'myfile.txt' you may execute the following to obtain the creation date of 'myfile.txt':
[dum,str] = dos('dir myfile.txt');
It is then necessary to parse the string, 'str', which is returned from the operating system. This can be done using the TEXTSCAN command. For example:
c = textscan(str,'%s');
createdate = c{1}{15}
Note that proper indexing into the variable 'c' may be platform dependent.
In order for the same MATLAB code to work on a Linux platform, the function ISPC can be used to determine whether the code is running on a PC or Linux platform. On Linux, the commands UNIX and LS work analogously to DOS and DIR.

More Answers (0)

MathWorks Support

Categories

Find more on File Operations in Help Center and File Exchange

Products


Release

R2007b

Community Treasure Hunt

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

Start Hunting!