Moving files to new folder based on timestamp
조회 수: 5 (최근 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!