0

I'm using this code to hash a single file:

const fs = require('fs');
let result = digest(fs.readFileSync('/users/ispedro/desktop/Test.PDF'));
console.log('Huella Digital MD5: ' + result)

I am trying to achieve the same but of all the files included in a folder, so that the output would be something like this:

The file (name of the file) generates the following MD5 hash: 175GKG3K6UZ6GAEE64BFKUN0MR

I have tried with various codes but have not succeeded ... any ideas please?

Update:

What I want to do is that the script reads the contents of a folder on the desktop without having to compress it in zip, so that I can remove or put files and when executing the script it returns the MD5 hash of those that are currently inside. I have tried to copy part of the code from this link npmjs.com/package/folder-hash which I think does exactly that but I can't get the script to work ...

Thank you very much to all.

ispedro
  • 1
  • 2
  • Does this answer your question? [How to generate an MD5 file hash in JavaScript?](https://stackoverflow.com/questions/14733374/how-to-generate-an-md5-file-hash-in-javascript) – evolutionxbox May 04 '21 at 13:25
  • You'll have to read the contents of each file in the folder, concatenate them and then run `digest` on that. – Sergiu Paraschiv May 04 '21 at 13:25
  • 1
    What have you tried so far? Where are you stuck? – Nico Haase May 04 '21 at 13:26
  • @SergiuParaschiv or maybe you can convert the entire folder into a compressed file like `zip` that would help reduce the problem i guess. – Ace May 04 '21 at 13:39
  • 1
    Sure, that's a solution too. I'm not sure how much entropy goes down because of compression though. – Sergiu Paraschiv May 04 '21 at 13:48
  • Thank you very much to all, what I want to do is that the script reads the contents of a folder on the desktop without having to compress it in zip, so that I can remove or put files and when executing the script it returns the MD5 hash of those that are currently inside. I have tried to copy part of the code from this link https://www.npmjs.com/package/folder-hash which I think does exactly that but I can't get the script to work ... – ispedro May 04 '21 at 14:32

0 Answers0