dir-command: import only files that have datenum between two dates
Afficher commentaires plus anciens
Hi everyone,
I am using the dir-command to get file information of many files in a directory (>800 000 files).
However, I only need the files with datenum between 01.01.2018 and 01.01.2019, which are significantly less files.
I was trying to work with cellfun, as shown in the MATLAB documentation of the dir command (https://de.mathworks.com/help/matlab/ref/dir.html):
MyFolderInfo = dir;
MyFolderInfo = MyFolderInfo(~cellfun('isempty', {MyFolderInfo.date}));
This is my current status:
date_2018 = datenum('2018/01/01 00:00:00','yyyy/mm/dd HH:MM:SS');
date_2019 = datenum('2019/01/01 00:00:00','yyyy/mm/dd HH:MM:SS');
listdir = dir(some_path);
listdir = listdir(cellfun(@(s) {s.datenum}<date_2019 && {s.datenum}>date_2018));
This gives the error:
Error using cellfun
Not enough input arguments.
So, obviously I'm not good with cellfun in general, but this is an example where I wanted to learn a bit about this tool.
Can anyone help me with this task?
Firstly, it's about getting rid of the not needed entries in the struct-variable. If this can be done with cellfun, that would be nice.
Thanks a lot in advance!
JE
Réponse acceptée
Plus de réponses (1)
Bob Thompson
le 31 Jan 2019
Modifié(e) : Bob Thompson
le 31 Jan 2019
0 votes
I don't know that cellfun is going to work on the dir results because they are an array of structures. You should be able to solve this using indexing alone.
Something like:
listdir = [listdir.date >= date2018 & listdir.date<= date2019];
Catégories
En savoir plus sur Time Series Objects dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!