Reputation: 43
I want to read an image file in MATLAB and use the time it was created in the system to add a delay for my next command. For ex if time_created is the system time the image file was created, I want my next command to execute after a delay of (time_now - time_created) + 3 sec. Is this possible?
Upvotes: 2
Views: 3264
Reputation: 1
With Python now really integrated into MATLAB, this works on both Windows and MacOS:
d1 =datetime(py.os.path.getctime('video_path'),'ConvertFrom','epochtime','TicksPerSecond',1,'Format','dd-MMM-yyyy HH:mm:ss.SSS');
Upvotes: 0
Reputation: 25232
You can use the information given by dir
:
yourFileName = 'myFile.m'
allfiles = dir
filenames = {allfiles(:).name}
[~,idx] = ismember(yourFileName,filenames)
yourFileDate = allfiles(idx).date
which will return a date string:
yourFileDate = 06-Mar-2014 10:53:48
or alternatively:
yourFileDate = allfiles(idx).datenum
which will give you the output in datenum format. (You probably want to work with that)
you could then continue as follows:
timeNow = clock %//current system time as date vector
timeFileCreation = datevec(yourFileDate) %//file creation time as date vector
timeDiff = etime(timeNow,timeFileCreation)
returns the number of seconds between both time vectors.
Upvotes: 2
Reputation: 11
Note that the matlab 'dir' command does not return the file creation time, but rather the last file modification time. In your use case, the creation time and the modification time are likely the same. But in other circumstances, the modification time may be different than the creation time (e.g. if a user edited a file after it was created). Different operating systems store different file times between the creation, last modification and last access times. Last modification time is the only one that is available in all operating systems that matlab runs on, so it is the only time supported by the matlab 'dir' command. Depending on with OS you're running on, you can access the other file times available on that OS, through (at least) use of the 'system' command and knowledge of the command line functions available in that OS.
Upvotes: 1