Compare directories with subdirectories and output how many files are the same from two different directories with same subdirectories.
2 次查看(过去 30 天)
显示 更早的评论
I need to count how many files are are different in two directories with subdirectories. So I want a program to run though the main directory, look through all the subdirectories and see which files are different from another main [student] directory (has the same files but they are randomized). So I need matlab to output how many files are correct when you compare the main directory versus the student directory. I will need to compare 20 students directories with the main directory. Which student has the closest match to the main directory wins a challenge. Here is what I have so far.
mainPath = '/Users/Documents/Lesson_Lisa_Italy_2015/';
studentsFolder = '/Users/Documents/Lesson_Lisa_Italy_2015 copy/';
choosenFolder = uigetdir(studentsFolder);
if choosenFolder == 0
return;
end
main = dir( mainPath );
user = dir( choosenFolder );
filenames = getAllFiles('/Users/Documents/Lesson_Lisa_Italy_2015/');
filenames = dir( filenames);
filenames_student = getAllFiles( choosenFolder );
for n = 2:numel(filenames)
names = char(filenames(n));
[pathstr,name,ext] = fileparts(names);
main( [main.isdir] ) = [];
user( [user.isdir] ) = [];
files_not_in_choosenFolder = setdiff( {main.name}, {user.name} );
files_not_in_mainPath = setdiff( {user.name}, {main.name} );
if isempty(files_not_in_choosenFolder) && isempty(files_not_in_mainPath)
disp( 'same files in the two folders' )
end
end
Thank you in advance!
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 File Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!