Moving files to new folder based on timestamp

5 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

dpb
dpb il 19 Lug 2019
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...

Più risposte (0)

Categorie

Scopri di più su Convert Image Type in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by