Logic to copy files into specific locations

2 views (last 30 days)
Hi there,
I need some help with creating a script that can copy and sort files into there respective folders.
1. I have a script that creates matfiles daily and sorts them into monthly folders. 2. These matfiles then need to be copied into a different location which contains folders created by day
I have included a screen shot for better understanding
Any help with what sort of logic I would need to use would be much appreciated.
Thanks,

Accepted Answer

Davide Ferraro
Davide Ferraro on 30 Aug 2012
Hi,
This is a possible approach:
files = dir('*.mat');
for i = 1:length(files)
datefolder = files(i).name(14:19);
mkdir(getdate)
copyfile('files(i).name',datefolder)
end
With the DIR command you get the names of the files in your folder (eventually you can also select wich file extension you want). With a simple loop you extract the date from the file name (based on your file this seems to be always in the same position so you only need to find the portion of your vection to extract). You may use this information to create the new folder (eventually reshaping it adding dashes or inverting the terms) and then with COPYFILE you can copy the file in the new folder.

More Answers (0)

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!