Writing the value of a registry in a file

currentKey = currentKey.getSubkey(key)

Lets assume I got currentKey. How can I print all the values in it, inside a .txt folder.
Or maybe in the messages.How do I get the values? The key might be SAM, or anything else. We have no idea what is it.