Moving files to new folder based on timestamp
2 次查看(过去 30 天)
显示 更早的评论
I need to make a code that moves files to a new folder. I know how to do this, but I need to move specific files. What I want to do is pull out files within a specific timestamp and move them to a new folder. I am not sure how to move only specific files and I am not sure how to select only the ones within a specific timestamp. Thank you
0 个评论
采纳的回答
dpb
2019-7-19
Return the dir() of the files matching desired pattern and then convert the .date field to datetime. You can then use whatever logic desired on it to select the matching indices...
d=dir('*.ext'); % return files of desired extension type
d.dt=datetime([d.datenum].','ConvertFrom','datenum'); % turn datenum into datetime
date1=datetime(...); % define your begin
date2=datetime(...); % end times...
ix=find((d.dt>=date1) & d.dt<=date2)); % vector of those wanted
for i=1:numel(ix)
movefile(d(ix(i))),'TargetLocation'); % define target for copy operation
end
With a suitable OS (under Windows I use the JPSoftware "TakeCommand" CLI, these operations are available as one-line batch commands that is a much simpler way to do so. I don't know about the MS CMD interpreter capability or other OS'es...
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Convert Image Type 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!