我们的目标是从MATLAB命令行中设置文件的create date ,并使用最少的JAVA命令。MATLAB's ability to process JAVA NIO commands is impeded by the auto-boxing需要让它们透明地工作,所以有必要调用它们参数的数组形式。
Starting from , one can use and the attribute.因为命令必须从MATLAB提示符发出,所以被测系统对JDK1.7有一个限制。
更新:
我试图在MATLAB中计算新的文件创建日期,如下所示,并避免使用FileTime.fromMillis(c.getTimeInMillis())
来设置文件创建日期(如果可能)。
问题:
是否有其他格式可以设置日期/时间= 9/1/18 16:00?已计算filedate
,但无法转换为正确的文件时间。
MATLAB命令:
p="C:DATA\testfile.txt"
filedate=1000*posixtime(datetime('2018-09-01 16:00','InputFormat','uuuu-MM-dd HH:mm','TimeZone','UTC'))
java.nio.file.Files.setAttribute(p, "creationTime", filedate, javaArray('java.nio.file.LinkOption', 0));
发布于 2018-09-26 07:26:18
用R2017A和JDK1.7测试的MATLAB m函数:
function SetCreateDate(STR_filename, posixdate)
% SetCreateDate(STR_filename, posixdate)
% STR_filename = 'C:\Data\my_testfile.dat'
% posixdate = posixtime(datetime('15-Sep-2018 16:00:01','InputFormat','dd-MMM-uuuu HH:mm:ss','TimeZone','America/New_York'))
filePath = strrep(STR_filename,'\','\\');
p = java.nio.file.Paths.get(filePath,javaArray('java.lang.String', 0));
filedate=posixdate*1000; % filedate is in milli-seconds
java.nio.file.Files.setAttribute(p, "creationTime", java.nio.file.attribute.FileTime.fromMillis(filedate), javaArray('java.nio.file.LinkOption', 0));
%%%% Additional Filetime Attributes that can be set
%java.nio.file.Files.setAttribute(p, "lastAccessTime", java.nio.file.attribute.FileTime.fromMillis(filedate), javaArray('java.nio.file.LinkOption', 0));
%java.nio.file.Files.setAttribute(p, "lastModifiedTime", java.nio.file.attribute.FileTime.fromMillis(filedate), javaArray('java.nio.file.LinkOption', 0));
其他属性可以在here中找到
名称类型- "lastModifiedTime“FileTime "lastAccessTime”FileTime "creationTime“FileTime "size”Long "isRegularFile“Boolean "isDirectory”Boolean "isSymbolicLink“Boolean "isOther”Boolean "fileKey“对象
仅当您成功使用此函数时,请向上选择此答案。
https://stackoverflow.com/questions/52506182
复制相似问题