Compare files present in excel file with the files present in a folder,if match found copy them into a new folder

1 次查看(过去 30 天)
Hello everyone,
I have an excel file which has 39 .art files and i have folder in my computer which has 4 subfolders,each subfolder has again 6 subfolders and inside one of these 6 subfolders .art files are present.now i want to search in every subfolder and compare the .art file names with the ones present in excel file.if match is found,copy the .art file present in the subfolder to another folder. Can anyone help me how to code this?

采纳的回答

Mohammad Sami
Mohammad Sami 2021-3-15
You can load your excel file using the readtable funtion.
myexcel = readtable('myexcel.xlsx');
You can the use the dir function to list all the dir files in the directory and its subdirectory.
mydir = 'C:\somedir\';
myartfiles = dir(fullfile(mydir,'**','*.art'));
You can then compare the filename and then copy them using the copy file function.
mycopydir = 'C:\copydir\';
samefiles = ismember({myartfiles.name},myexcel.name);
filestocopy = myartfiles(samefiles);
for i = 1:length(filestocopy)
origpath = fullfile(filestocopy(i).folder,filestocopy(i).name);
destpath = fullfile(mycopydir,filestocopy(i).name);
copyfile(origpath,destpath);
end
  4 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 File Operations 的更多信息

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by