How to make matlab access two folders for data when separated by date

1 view (last 30 days)
I'm trying to move some of the older data into a new folder (ex: move pre2020 files from folder_new to folder_old, and leave the 2020~ files in the folder_new).
Problem is that there are some functions where the user needs to analyze files in both folders (ex: data from Dec 2019 to Feb 2020)
How should I proceed with this?
I was thinking about using an if statement, but not sure how to make matlab look at both folders when a function needs data from both folder_new and folder_old.
Folder structure is via
year
->month
-->date
--->hour
---->min

Answers (1)

Benjamin Thompson
Benjamin Thompson on 1 Jul 2022
Edited: Benjamin Thompson on 1 Jul 2022
You can get file dates using the "dir" function or keyword in MATLAB. Does any of this help?
>> D = dir
D =
105×1 struct array with fields:
name
folder
date
bytes
isdir
datenum
>> D(1).date
ans =
'17-Jun-2022 20:41:47'
>> datetime(D(1).date) > datetime(2020, 1, 1)
ans =
logical
1
>> datetime(D(1).date) > datetime(2022, 6, 18)
ans =
logical
0
  2 Comments
Emily
Emily on 1 Jul 2022
Are you referring to the classdef and properties?
I don't know much about them
Benjamin Thompson
Benjamin Thompson on 1 Jul 2022
No this does not use a class in MATLAB. I showed an example here how to use the output of the dir command in MATLAB to compare a file date to some other date that you are interested in. Then based on whether the result is true or false you can use an "if" statement to move or copy it. If you find the MATLAB help article on "File Operations" you can see links to all the MATLAB functions that work on files. You probably want movefile or copyfile.
Now I was not very clear on what you were trying to do. If this is not helping you may want to add a simple example of what you are trying to do to this thread.

Sign in to comment.

Categories

Find more on File Operations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!