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

1 visualizzazione (ultimi 30 giorni)
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?

Risposta accettata

Mohammad Sami
Mohammad Sami il 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 Commenti

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su File Operations in Help Center e File Exchange

Prodotti


Release

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by