Logic to copy files into specific locations

1 回表示 (過去 30 日間)
Aadil
Aadil 2012 年 8 月 30 日
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,

採用された回答

Davide Ferraro
Davide Ferraro 2012 年 8 月 30 日
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.
  1 件のコメント
Aadil
Aadil 2012 年 8 月 31 日
Thanks for this!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by