Moving files to new folder based on timestamp
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
dpb
le 19 Juil 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...
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Convert Image Type dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!