gpt4 book ai didi

MATLAB:获取文件的最后修改时间

转载 作者:行者123 更新时间:2023-12-02 01:10:51 25 4
gpt4 key购买 nike

我正在寻找执行某些例程(更新 file.m)的 MATLAB 代码,如果 file.csvfile.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 代码。其余的工作(Evaluate variables in external file strings)。

最佳答案

您可以使用 MATLAB 的 dir 提取文件的修改时间命令。像这样的东西:

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 中序列日期格式。

关于MATLAB:获取文件的最后修改时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17522463/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com