finding simillar folders (size and number of files anf files name)
1 回表示 (過去 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!