How to get creation date of files
Mostra commenti meno recenti
How can I get the creation date of file? I can get modified date with dir command but not the creation date.
Risposta accettata
Più risposte (4)
Guillaume
il 8 Giu 2016
On windows you can simply delegate to .Net
d = system.IO.File.GetCreationTime(fullpath)
1 Commento
Austin Spencer
il 10 Giu 2019
Thanks for the info, this is a nice clean solution! By comparison parsing the return from "dir" seems to be very fragile and is inherently platform dependent.
One correction: at least for my case, "system" must be capitalized.
d = System.IO.File.GetCreationTime(fullpath);
The resulting .NET DateTime object can then be converted into a MATLAB datetime object.
creationDateTime = datetime(d.Year, d.Month, d.Day, d.Hour, d.Minute, d.Second);
Sam Raymond
il 5 Mag 2021
With python now very much integrated into MATLAB (R2021a), a nice way to get this is the following:
d1 = datetime(py.os.path.getctime('video_path'),'ConvertFrom','epochtime','TicksPerSecond',1,'Format','dd-MMM-yyyy HH:mm:ss.SSS');
On Mac OSX (tested 2019-01-29 using Mojave and Matlab R2018a) use:
[a,b]=system('GetFileInfo myfile.m'); s=strfind(b,'created: ')+9; crdat=b(s:s+18)
or
fname='myfile.m'
[a,b]=system(sprintf('GetFileInfo "%s"',fname)); s=strfind(b,'created: ')+9; crdat=b(s:s+18)
datestr(datenum(crdat))
Konstantin
il 26 Gen 2023
Why not like this?
file_info = dir(path_to_file)
1 Commento
Stephen23
il 26 Gen 2023
"Why not like this?"
The question asks for the file creation date. DIR() returns the file modification date:

This is explained in the DIR() documentation:
Categorie
Scopri di più su Startup and Shutdown in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!