View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from

4.9 | 8 ratings Rate this file 20 Downloads (last 30 days) File Size: 16.5 KB File ID: #24671 Version: 1.6



Jan Simon (view profile)


08 Jul 2009 (Updated )

Get and set the times for creation, access and modification of a file or folder (Windows only)

| Watch this File

File Information

These MEX-functions get and set the creation, access and write times of a file under Windows.

SetFileTime(FileName, Spec, DateVector, Type)
  FileName: File or folder name, absolute or relative path.
      Unicode names and UNC paths are accepted.
  Spec: String, 'Creation', 'Access', 'Write'.
  DateVector: [1 x 6] double vector (see DATEVEC) or UINT64.
  Type: Optional, conversion method from local to UTC time.

Time = GetFileTime(FileName, Type, OutType)
  FileName: File or folder name, absolute or relative path.
  Type: Optional, conversion method from UTC to local time.
  OutType: Optional, all three times as struct or a single time.
  Time: Struct with fields 'Creation', 'Access', 'Write' or
        one time, [1x6] DATEVEC or UINT64 format.

The Local<->UTC conversion needs Windows XP, Windows Server 2003 or higher. The LCC 2.4 compiler shipped with Matlab does not know the "new" time function.

Precompiled mex files can be downloaded at:

Tested: Matlab 6.5/2009a, WinXP, 32 bit, OWC1.8, BCC5.5, LCC 3.8, MSVC 2008
Compatibility to 64 bit Windows is assumed.

MATLAB release MATLAB 7.8 (R2009a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (14)
28 Nov 2016 Qingyu

Qingyu (view profile)

Works as description!

18 Oct 2016 Josh

Josh (view profile)

Thanks Jan. People like you make this a special place dude.

16 Oct 2014 Rusty Shackleford

Exactly what I needed. Let me emphasize to users that you must have the pre-compiled mex file!

03 Jul 2014 harun artuner

very usefull dll for me.
thanks alot.

18 Jun 2013 David Hildebrand

02 Feb 2013 Artik Crazy

11 Dec 2011 Lasse

Lasse (view profile)

Thanks so much for this!
Is i possible to make a 'DateTaken'?

Comment only
29 Nov 2010 Jan Simon

Jan Simon (view profile)

@Emile: I'm happy that offering the binaries helped!
Which compiler did you use? In the documentation of SetFileTime you find a warning that LCC shipped with Matlab (at least up to 2009a) does not recognize TzSpecificLocalTimeToSystemTime. Very sad, because this function is not really brand new.
I found some workarounds in the net, but the source is much longer and complicated than the SetFileTime source.

Comment only
29 Nov 2010 Emile Demarteau

Dear Jan,

Your function looks really promising, however I cannot compile the function, as matlab returns an error on the TzSpecificLocalTimeToSystemTime function. I am running matlab 7.5 on XP so this should support this functon.

Alternatively I commented out the error warning which uses this function. Now compilong works, however the function still return an error: 'SetFileTime: Time to FILETIME failed!' or ''Too many input paramters"

Finally, your precompiled dll's fixed the problem.

So thanks for putting this online!


Comment only
14 Oct 2010 Jan Simon

Jan Simon (view profile)

@Drew: Sorry, I forgot to mention explicitely, that the C-file has to be compiled before it can be used.
At first setup your compiler by "mex -setup", if not done before. Then compile as mentioned in the C-file: "mex -O GetFileTime.c" and "mex -O SetFileTime.c".
If you run a 32bit Matlab, I offer pre-compiled Mex files on the named webpage.
Unfortunately I'm not allowed to distribute compiled files here in the FEX.

Comment only
14 Oct 2010 Drew

Drew (view profile)

This is the first time I've downloaded from the FEX, so please excuse me if I'm making a trivial mistake; however, I am unable to get this to run.

When I try to use GetFileTime.m I see:

??? Error using ==> GetFileTime at 77
*** GetFileTimeCannot find MEX script!

I then tried running the uTest_FileTime.m and received a similar response:

=== Test SetFileTime / GetFileTime 14-Oct-2010 12:04:21
Create test file:
name: 'FileTime__.test'
date: '14-Oct-2010 12:04:21'
bytes: 0
isdir: 0
datenum: 7.3443e+005

??? Error using ==> GetFileTime at 77
*** GetFileTimeCannot find MEX script!

Error in ==> uTest_FileTime at 59
Reply = GetFileTime(File);

Any thoughts? Thank you very much.

Comment only
11 Nov 2009 Jan Simon

Jan Simon (view profile)

@Bass: I've submitted a new version with an improved UTC<->local time conversion. Now with the default conversion, GetFileTime replies the same time as the DIR command of Matlab 7. UTC times and the Windows-like times depending on the current daylight saving time are possible also.
Thanks for finding this problem!

Comment only
05 Nov 2009 Bass

Bass (view profile)

Useful function.
Beaware, however that the times return by this function do not necessarily match those return by the MATLAB dir function. This seems to because Windows add an hour when reporting the time during daylight savings time (even if the file wasn't created during daylight savings time. See
MATLAB however does not do this.

I this function appears to return the Windows time. So I have run into problems when using the two functions together.

24 Aug 2009 Aurelien Queffurust

Very useful to get the creation time of files since the DIR output doesn't return this information

11 Nov 2009 1.1

UTC<->local time conversion more consistent now and flexible. Thanks Bass for pointing to this problem!

20 Nov 2009 1.2

Access folders also

20 Aug 2010 1.3

Test function failed, if DIR replies localized names for dates as e.g. the German "24-Dez-2010". No problems for English OS versions and in the actual functions.

01 Oct 2010 1.4

Accept unicode names.
Another fixed bug in the test function concerning local month names.

01 Oct 2010 1.5

Consider Unicode file names.
Another fixed bug concerning local month names in the test function.

29 Jun 2011 1.6

Times can have native UINT64 format. GetFileTime can reply a single time, e.g. just 'Access' time.

Contact us