how to check the path of each file and compare it with a string and if it matches copy them into new folder?

13 views (last 30 days)
hello, i need to make a function in which there will be 3 parameters...first two arguments will be source folder and destination folder address respectively.and third will be a folder name. in the source folder there are 6 subfolders in which 3 folders are having _201_ digit in their name and next three are having _678_ in their name.
The three folders having in their name _201_ contain some .art files and folders having _678_ also have same .art files. and also it will take an excel file from user.
now,the function will check for every file in all the subfolders of source folder and compare its name with that in excel file if the name matches.it will store the path of the file of source folder and check in its path if the name which is given in the third argument( i.e _201_ or_678_) matches with the path. if it matches, then copy that file into destination folder.otherwise show that file as duplicate file in command window. and also after the files are copied i have to show how many files are copied in the destination folder
This is the code which i wrote.please help me further to complete the function.
function myfunction(source,destination,foldername)
[~,~,file] = uigetfile('*.xlsx');
myexcel=xlsread(file); %read the excel file
addpath(genpath(source)); %add the source folder address to path
myfiles=dir(fullfile(source,'**', '*.art'));
end

Answers (1)

Image Analyst
Image Analyst on 25 Mar 2021
You don't need addpath() - just use fullfile(). To compare strings, use ismember(), contains(), and/or strfind().

Categories

Find more on Tables in Help Center and File Exchange

Tags

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!