finding simillar folders (size and number of files anf files name)
2 次查看(过去 30 天)
显示 更早的评论
In an specified folder there are some folders for example in these names:a,b,c,d,e,f,... .In each of these folders also there are some .xls files. Sometimes same .xls files are inside some of them. for example the same .xls files that are inside 'a', there are also in folder 'd' too. (exactly the same names and size and numbers of .xls files).
now its needed finding these similar folders that inside them are the same. and then renaming one of them to '(numbers of .xls file)' and deleting others similar. for example inside of 'a','f','e','w','f','c' are same and inside of these are the same 16 .xls files. it's needed deleting 'f','e','w','f','c'. then renaming 'a' to '(16)'
we could determine these similar folders from the size of them also and i think this is the simplest way (but not accurate because maybe exist 2 folder in same size but not same inside)
2 个评论
Jan
2011-9-19
What exactly is the size of a folder? Are you looking for similar or equal files? Would a checksum of the files or of all files insider a folder (and subfolders?) help?
回答(1 个)
Jan
2011-9-19
aDir = dir(FolderName);
isFile = not([aDir.isdir]);
fileSize = [aDir(isFile).size];
Hash = DataHash(sort(fileSize));
Now the number of the files is considered also and the sizes of the different files. It would be more accurate to use the names and dates also:
aDir = dir(FolderName);
isFile = not([aDir.isdir]);
Hash = DataHash(aDir(isFile));
Now you can store a list of already occurred Hash values in a cell string and if any(strcmp(Hash, HashList)) is TRUE, delete the folder, if FALSE rename it.
4 个评论
Jan
2011-9-19
In general validity is more important than speed. Creating a wrong result with a high speed will lead to troubles, creating a correct result slowly will increase the consumption of coffee.
另请参阅
类别
在 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!