Borrar filtros
Borrar filtros

Have dir() only accumulate files between certain dates

1 visualización (últimos 30 días)
Is there a way to make the dir() function only accumulate files from between certain dates?
I have the following code,
S = dir(fullfile(SomePath,'**/*.xls'));
Which accumulates all the xls files in the "SomePath" directory. The SomePath directory contains upwards of 10,000 folders each with potentially 5 or 6 xls files in them. Needless to say, the command takes a significant amount of time to run, about 15 mintues.
I have this line in a function that looks for a specifc one of the xls files in the SomePath directory. Based on various inputs to this function I should know within a range of about 10 days of when the file should have been added to the SomePath directory.
Is there a way to make dir only look at that range of 10 days instead of all the folders and xls files in the SomePath directory?

Respuesta aceptada

Walter Roberson
Walter Roberson el 13 de Nov. de 2023
Is there a way to make the dir() function only accumulate files from between certain dates?
No, there is not.
I notice you used forward slash as your directory separator -- which is valid on all supported operating systems. But people who use Windows tend to use \ instead of / in their paths.
If you happen to be using MacOS or Linux, I suggest you consider system() of a find() https://ss64.com/osx/find.html call
start_days_ago = 23; %for example
days_window = 10; %within a range of about 10 days
start_days_ago = start_days_ago;
end_days_ago = (start_days_ago - days_window);
cmd = "find " + '"' + SomePath + '"' + " -depth -name \*.xls -ctime -" + start_days_ago + " -a -ctime +" + end_days_ago + " -print";
[status, msg] = system(cmd);
filenames = regexp(msg, '\r?\n', 'split');
filenames(cellfun(@isempty, filenames)) = []; %can happen especially at the end of list
Now filenames should be a cell array of character vectors of filenames qualified relative to whatever was in SomePath

Más respuestas (0)

Categorías

Más información sobre File Operations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by