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

**URL:** <https://discuss.ipfs.tech/t/is-it-possible-to-generate-parent-folders-hash-from-its-files-hash/7590>\
**Category:** Uncategorized\
**Created:** [March 30, 2020, 6:45pm UTC](https://discuss.ipfs.tech/t/is-it-possible-to-generate-parent-folders-hash-from-its-files-hash/7590 "2020-03-30T18:45:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![avatar-lavventura](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/avatar-lavventura/32/2890_2.png) [@avatar-lavventura](https://discuss.ipfs.tech/u/avatar-lavventura)\
**Post date:** [March 30, 2020, 6:45pm UTC](https://discuss.ipfs.tech/t/is-it-possible-to-generate-parent-folders-hash-from-its-files-hash/7590/1 "2020-03-30T18:45:30Z")

</div>

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:

```auto
❯ 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 `?

---

<div class="post-metadata">

**Author:** ![RubenKelevra](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/rubenkelevra/32/3390_2.png) [@RubenKelevra](https://discuss.ipfs.tech/u/RubenKelevra)\
**Post date:** [April 1, 2020, 12:44am UTC](https://discuss.ipfs.tech/t/is-it-possible-to-generate-parent-folders-hash-from-its-files-hash/7590/2 "2020-04-01T00:44:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![avatar-lavventura](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/avatar-lavventura/32/2890_2.png) [@avatar-lavventura](https://discuss.ipfs.tech/u/avatar-lavventura)\
**Post date:** [April 1, 2020, 12:15pm UTC](https://discuss.ipfs.tech/t/is-it-possible-to-generate-parent-folders-hash-from-its-files-hash/7590/3 "2020-04-01T12:15:36Z")

</div>

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?
