Is it possible to generate parent folder's hash from its files' hash

If a folder has few different files/folders, how will be the main folder’s hash is obtained ? If we know the hash of the files from them could we generate the parent folder’s hash?

Let’s say:

❯ ipfs add -r .
added QmWfVY9y3xjsixTgbd9AorQxH7VtMpzfx2HaWtsoUYecaX doo/hello
added QmNyJpQkU1cEkBwMDhDNFstr42q55mqG5GE5Mgwug4xyGk doo/world
added QmVmHiVReNAmiucZM44tbLErg38HPLA6sG7oJVYF1i3Fr4 doo

On a different machine I only have its files’ hashes.
=> So by using: QmWfVY9y3xjsixTgbd9AorQxH7VtMpzfx2HaWtsoUYecaX and QmNyJpQkU1cEkBwMDhDNFstr42q55mqG5GE5Mgwug4xyGk can I generate the parent folder (doo)'s hash, which is QmVmHiVReNAmiucZM44tbLErg38HPLA6sG7oJVYF1i3Fr4 ?

Well, If you use -w on the add, a folder wrapping the files will be generated (this will also maintain the filenames, which are otherwise lost).

To generate the exact same folder ID you need additional information apart from the IDs of the file: the file size.

How a ‘folder’ looks like under the hood is pretty simple, it’s a json object.

Take a look at one via ipfs object get

But since IPFS is a network protocol, you can simply do the following:

You get the Hash from the folder on one computer via ipfs files stat --hash /foldername and add the folder on a different company:

ipfs files cp /ipfs/<CID> /foldername

The content of this folder is actually not transferred when the command is called. Just the directory node is fetched.

When you want the whole folder to be locally stored you have to pin the folder.

The reasoning behind this so called lazy add is simple: you ususally don’t want the whole data, maybe you just want to navigate to a specific file. That’s easier when the folder is already mapped in your MFS.

Additionally you can map the folder on one computer, add a file and transfer the new CID back to the first computer and replace the folder with the new version.

Is it possible for you to provide a simple example to obtain the folder-hash?

=> Can I extract the json object of the folder? and from it re-create its parent’s hash?