Compare files present in excel file with the files present in a folder,if match found copy them into a new folder
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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?
0 commentaires
Réponse acceptée
Mohammad Sami
le 15 Mar 2021
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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur File Operations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!