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

조회 수: 2 (최근 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