MATLAB:获取文件的最后修改时间 [英] MATLAB: Get the last modification time of a file
本文介绍了MATLAB:获取文件的最后修改时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找可以执行某些例程(更新 file.m
)的MATLAB代码,如果对 file.csv
的编辑比对 file.m的编辑要近的话
.
I am looking for MATLAB code that does some routine (updates a file.m
), if file.csv
is edited more recently than file.m
.
应如下所示:
% Write time extraction
tempC = GetFileTime('file.csv', [], 'Write');
tempdateC = tempC.date
tempM = GetFileTime('file.m', [], 'Write');
tempdateM = tempM.date
% Write time comparison
if numel(dir('file.m')) == 0 || tempdateC >= tempdateM
matDef = regexprep(fileread('file.csv'), '(\r\n|\r|\n)', ';\n');
f = fopen('file.m', 'w');
fwrite(f, ['Variable = [' matDef(1:end) '];']);
fclose(f);
end
用于时间戳提取的行似乎是不正确的MATLAB代码.其余的有效(评估外部文件字符串中的变量).
The lines for timestamp extraction seem to be incorrect MATLAB code. The rest works (Evaluate variables in external file strings).
推荐答案
You can extract the modification time of a file using MATLAB's dir
command. Something like:
function modTime = GetFileTime(fileName)
listing = dir(fileName);
% check we got a single entry corresponding to the file
assert(numel(listing) == 1, 'No such file: %s', fileName);
modTime = listing.datenum;
end
请注意,输出位于MATLAB的 datenum
序列日期格式.
Note that the output is in MATLAB's datenum
serial date format.
这篇关于MATLAB:获取文件的最后修改时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文