How to assign different files in the target folders?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Ashfaq Ahmed
il 8 Mar 2022
Commentato: Ashfaq Ahmed
il 9 Mar 2022
Hi all!
Suppose, I have several files in a folder named like this:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/919039/image.png)
Please note that 20150408 means 2015-April-08.
Now I want to write a code that will go through all these files and will generate folders for each of the day in the same directory. For example, all the files that contains day 08's data with be moved to a folder named "Day08". Similarly, for day 09's data, it will be in "Day09" folder. I have a months of data and it contains files from day 01 to day 31.
Could you please give me an idea on how to efficiently write this code?
0 Commenti
Risposta accettata
Stephen23
il 8 Mar 2022
P = 'absolute or relative path to where the files are saved';
for k = 1:31
D = sprintf('Day%02d',k);
mkdir(P,D)
X = fullfile(P,sprintf('*%02dT*.nc',k));
Y = fullfile(P,D);
movefiles(X,Y)
end
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!