问题
I can get modification time in matlab by:
>> f = dir('my_filename.dat');
>> f.date
But how can I change it?
回答1:
This is can be done using Java&Matlab:
import java.io.File java.text.SimpleDateFormat
f = File('my_filename.dat');
sdf = SimpleDateFormat('HH:mm dd/MM/yyyy');
newDate = sdf.parse('12:34 10/12/2010');
f.setLastModified(newDate.getTime);
回答2:
To set the date to the current date you can write something to the file:
fid = fopen('my_filename.dat', 'r+');
byte = fread(fid, 1);
fseek(fid, 0, 'bof');
fwrite(fid, byte);
fclose(fid);
Here, I read a single byte from the beginning of the file, and I write it back.
If you want to set it to something else, you can do it with a system call. On linux you can use touch for that:
system('touch -d "2012-10-01" my_filename.dat');
Similar command exists for windows (Touch) in the Win32 Console ToolBox 1.0
回答3:
Building on the Java solution:
function setFileDate(fn,date)
% date needs to be UTC I think
java.io.File(fn).setLastModified(etime(datevec(date),[1970 1 1 0 0 0])*1000);
Or
function updateFileDate(fn)
java.io.File(fn).setLastModified(java.lang.System.currentTimeMillis)
来源:https://stackoverflow.com/questions/13030143/set-modification-time-in-matlab