Coding to extract specific files from two original folders into a new folder

5 ビュー (過去 30 日間)
Emily Platt
Emily Platt 2021 年 4 月 26 日
回答済み: Clayton Gotberg 2021 年 4 月 26 日
I want to make a script that goes through data I have in two seperate folders, and extracts the files I specify into a new folder. The specific files I want in the new folder are listed on a separate excel file. How would I code this?

回答 (1 件)

Clayton Gotberg
Clayton Gotberg 2021 年 4 月 26 日
You can use movefile or copyfile to put files in one place into another.
This is a sketch of the code, you'll need to change quite a lot to get this to work:
start_location = 'C:/MATLAB/experiment_results/';
end_location = 'C:/MATLAB/selected_results/';
desired_files = <'list from excel'>;
for k = 1:length(desired_files) % for each file you want to move
file_start_location = [start_location desired_files(k)];
% Will construct a full filepath, like
% 'C:/MATLAB/experiment_results/20210425.txt'
file_end_location = [start_location desired_files(k)];
movefile(file_start_location,file_end_location);
end

カテゴリ

Help Center および File ExchangeData Import from MATLAB についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by