Adding already pinned files to immutable folder

Is there a way to add already pinned files to an immutable folder without having to cat and then re-add them?

I have lots of files already pinned and I’d like to add them to a folder where I get a single folder CID that contains the files. I’m aware I can do this by adding the files to ipfs using ipfs.add, setting the wrapWithDirectory option to true and then setting the path option to myFolderName/myFile.txt which gives me two CIDs (one for the file and one for the directory). But I already added my files to ipfs, so how can I add them to a folder without re-downloading (ipfs.cat) them and then re-uploading (ipfs.add) them?

The easiest way would be to put your files into MFS. (see ipfs files *) commands. Or you can use the ipfs object patch add-link command

2 Likes

@int were you able to figure this out? I have a set of hashes and I want to group them under one folder. I have been looking at IPLD and creating a dag of all the hashes and it’s children…

@Botch zac’s answer above was correct.

Step 1: create the object to wrap the files (the root CID):

Step 2: add each file one at a time like with patch

If I remember correctly each time you add a new link you get a new root CID so be aware of that. I’m not sure there’s a way to add multiple links in a single call, but I wish there was. Please let us know if you find out I’m wrong about multiples. thanks!

1 Like