Have dir() only accumulate files between certain dates
2 ビュー (過去 30 日間)
古いコメントを表示
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?
0 件のコメント
採用された回答
Walter Roberson
2023 年 11 月 13 日
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
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で File Operations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!