matlabfilefileinfo

How can I get file creation dates in Matlab?


I'm trying to get the file list sorted by creation dates for a bunch of xlsx files in the folder ad_dir='C:\AT files\'. Using the Matlab dir function will give me the last modified dates which is no good for me.

I've tried running the following Python code:

flist = py.sorted(py.glob.glob([ad_dir '*.xlsx']),'key',py.os.path.getctime, 'reverse',True);

but I keep getting Python Error:

TypeError: getctime() missing 1 required positional argument: 'filename'

I'm using Matlab R2018a.


Solution

  • You can use a method from .Net's System ( documentation ).

    This can be done directly within MATLAB as if is was a MATLAB function because the library you need should already be loaded, see the MATLAB docs for calling .NET

    fullpath = 'C:\FolderA\FolderB\MyFile.xlsx';
    c = System.IO.File.GetCreationTime(fullpath);
    

    c is a structure with all of the components needed for datetime if you want, e.g.

    created = datetime(c.Year, c.Month, c.Day, c.Hour, c.Minute, c.Second);