It doesn't work in that way.
MD5 hashing works on byte sequences. When you take the MD5 checksum of a file, you are using the file's whole range as the input sequence. However, it doesn't make sense for a directory because it is not represented in the same way as a non-directory file. What defines a (regular) "file" is a set of operations that can be done to it, and not all of these operations can be applied to a directory.
To generate the hashes of all files in a directory, simply take the sum of it's files recursively.
Code:
$ find foo/ -type f -exec md5sum {} \; > SUMS
where foo is the directory to be checked and SUMS is the output file containing a table of hash value -- file path pairs. Be sure don't put the file SUMS under foo itself, otherwise funny things will happen.
The ">" operator in the above code truncates the file SUMS if it's already there. If this is not desired, change it to ">>", which allows the output to be appended to the file.
To check the files' integrity, just use
and the program will take care of the rest.
There's a caveat though. The paths saved in the SUMS file are affected by the path argument passed to "find". If you did "find foo/ ..." they would look like "foo/bar/baz ..." but if you did "find ./foo/" they'd be "./foo/bar/baz ...". Be sure you don't confuse md5sum when you are checking the files. One of the situations may be like this: you recorded in the SUMS the *absolute* paths of each file, and later you copied the directory tree to another place so the absolute paths changed. After that, md5sum will complain that it can't find the files to check.
Alternatively you can just archive the whole directory to a .tar file and take the checksum of that. However by doing so you lose the information of each individual file's checksum.