MATLAB:获取文件的最后修改时间
如果MATLAB:获取文件的最后修改时间,matlab,timestamp,Matlab,Timestamp,如果file.csv比file.m编辑得更晚,我正在寻找执行一些例行程序(更新file.m)的MATLAB代码 应该是这样的: % Write time extraction tempC = GetFileTime('file.csv', [], 'Write'); tempdateC = tempC.date tempM = GetFileTime('file.m', [], 'Write'); tempdateM = tempM.date % Write time comp
file.csv
比file.m
编辑得更晚,我正在寻找执行一些例行程序(更新file.m
)的MATLAB代码
应该是这样的:
% 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代码。其余部分工作()。您可以使用MATLAB命令提取文件的修改时间。比如:
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的串行日期格式。至少,这不适用于存储在UNC路径文件服务器上的文件。它返回创建日期/时间(或者可能是缓存的mod时间)。请忽略^^。(无法删除它。)