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

1 visualización (últimos 30 días)
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?

Respuesta aceptada

Mohammad Sami
Mohammad Sami el 15 de Mzo. de 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 comentarios

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre File Operations en Help Center y File Exchange.

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by