Moving files to new folder based on timestamp

5 ビュー (過去 30 日間)
Matthew Fleming
Matthew Fleming 2019 年 7 月 19 日
回答済み: dpb 2019 年 7 月 19 日
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

採用された回答

dpb
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 件)

カテゴリ

Help Center および File ExchangeConvert Image Type についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by