[Solved] Duplicate finder
-
wrote on 24 Jan 2011, 18:51 last edited by
Volker, I've thought where it should be moved too, but forgot about brainstorm and left it to someone who will have some ideas. Thanks.
-
wrote on 24 Jan 2011, 18:59 last edited by
Maybe i've misunderstood something, but how can md5 ot sha1 help me with finding dublicates? I thought that its cryptohraphic algorithms for government use :)
-
wrote on 24 Jan 2011, 19:06 last edited by
If two hashes are equal then it is very likely that the two files they are computed of bitwise equal content (although not guaranteed as the set of all possible file contents is indefinite, whereas the number of possible hashes is limited and thus there cannot exist an isomorphic relation between them). You can store the hashes in a database and search for duplicates in that. For "similar" files you'll have to go with Levenshtein or other means, as Denis stated.
-
wrote on 24 Jan 2011, 19:28 last edited by
But how can i store file info in a hash ?
-
wrote on 24 Jan 2011, 19:30 last edited by
You can pass it contents through hash function and you will have it hash at the end.
-
wrote on 24 Jan 2011, 19:43 last edited by
[quote author="alex.dadaev" date="1295897294"]But how can i store file info in a hash ?[/quote]
You cannot. This "web page":http://lmgtfy.com/?q=hash+function has some explanations for you.
-
wrote on 24 Jan 2011, 20:25 last edited by
Okay :)
-
wrote on 24 Jan 2011, 20:50 last edited by
Is there any way to use QHash methods in QCryptographicHash ?
I'd like to make a comparing table for files that i hash. -
wrote on 24 Jan 2011, 20:57 last edited by
QHash is a hash table, a datastructure optimized for random access based on a key value.
QCryptographicHash is used to calculate cryptographic hash values from input data. They are completely different things:-)
So, no, you can not use QHash's methods in QCryptographicHash. Just use the result of a QCryptographicHash as a key to a QHash and you should be set. Just make sure to reset the QCryptographic hash whenever you are done with a file, or you will not get the same hash values for the same files (since the second one will still have all the data of the first one "prepended").
-
wrote on 24 Jan 2011, 21:12 last edited by
Yes, that's possible. You can use the following function as a start for your project:
@
#define MY_SHA1_BUFFER_SIZE 4096QString getSha1HashFromFile( const QString &fn )
{
QCryptographicHash ch( QCryptographicHash::Sha1 );
QFile file( fn );
if( !file.open( QIODevice::ReadOnly ) )
return QString();char buf[MY_SHA1_BUFFER_SIZE]; while( !file.atEnd() ) { qint64 read = file.read( buf, MY_SHA1_BUFFER_SIZE ); ch.addData( buf, read ); } file.close(); return QString( ch.result.toHex() );
}
@ -
wrote on 25 Jan 2011, 11:44 last edited by
how can i make QString from QFileInfoList ?
is there any possibilities to do that? -
wrote on 25 Jan 2011, 12:19 last edited by
QFileInfo::path() ???
-
wrote on 25 Jan 2011, 12:19 last edited by
No.
QFileInfoList is a typedef for QList<QFileInfo>.
You know how many properties a QFileInfo object describing a single file has, don't you?
If you want a single string from these big bunch of information you will have to construct it yourself.
-
wrote on 25 Jan 2011, 12:30 last edited by
Ok, forgpot to add the iteration by for(...)...
-
wrote on 25 Jan 2011, 12:35 last edited by
but how can i construct a path of a single file?
-
wrote on 25 Jan 2011, 12:41 last edited by
Read the docs on "QFileInfo":http://doc.qt.nokia.com/stable/qfileinfo.html - we did it too. Everything you need is documented there. Yes, it takes some 5 minutes to read it all through, but if you're too lazy we can't help you. If you have concrete questions or problems with any of the methods, ask them.
-
wrote on 25 Jan 2011, 12:41 last edited by
If you read the documentation, you would find it ...
@
QFileInfoList list;
for(int i = 0; i < list.size(); ++i)
{
QString filePath = list[i].absoluteFilePath();
{
@ -
wrote on 25 Jan 2011, 12:57 last edited by
i've made it by myself already :) the reason why i ask so dumb questions is because i'm just starting using Qt and programming itself and i just want not to make stupid mistakes.
@QString path[list.size()];for (int i = 0; i < list.size(); ++i) {
QFileInfo fileInfo = list.at(i);
path[i] = fileInfo.path();}@ -
wrote on 25 Jan 2011, 13:01 last edited by
I would suggest using a QStringList instead of QString path[xx];
-
wrote on 25 Jan 2011, 13:04 last edited by
First: Then show us your code and we comment on it; Don't ask dumb questions that are clearly answered in the very good API docs the Trolls have created for us. It is very likely that you will not get any answer (apart from "RTFM"). We all put some valuable amount of time into DevNet to answer questions - with that silly game you are stealing this time!
Second: Do not use C-Style arrays in C++ if you are not absolutely forced to. Use the fine "Container Classes":http://doc.qt.nokia.com/stable/containers.html of Qt (or the equivalents of C++ standard library or boost). In your case "QStringList":http://doc.qt.nokia.com/stable/qstringlist.html is what you want.
Third: C-Style arrays of unknown size at compile time are not supported by all compilers and therefore not portable. I leave you to google or bing to search for the details.
13/40