I have a question that is there a way other than manual do it to merge two folder using their cid? Like folder with cid xxx has file abc, and folder with cid yyy has file def, something command like ipfs merge xxx yyy will give cid zzz that contains file abcdef? Assume there are no conflict file, or with a merging option.
I don’t think this feature is built-in so I threw this Python script together, hope it helps!
import requests, json, sys
# Usage: ipfs_merge_dir.py <dir1> <dir2> [dir3 dir4...]
# Address of node to use
NODE = "http://localhost:5001"
API = "/api/v0/"
TEMP = "/merge_tmp"
# Creates temp dir in MFS, removing existing one if present
req = requests.post(NODE+API+"files/mkdir?arg="+TEMP)
# Removes temp dir (and contents) from MFS
req = requests.post(NODE+API+"files/rm?arg=%s&force=true" % TEMP)
# Returns CID of the temp dir
req = requests.post(NODE+API+"files/stat?arg=" + TEMP)
data = json.loads(req.text)
# Copies contents of CIDs to temp dir
req = requests.post(NODE+API+"ls?arg="+cids)
dirData = json.loads(req.text)
if "Type" in dirData and dirData["Type"] == "error":
for obj in dirData["Objects"]:
if len(obj["Links"]) == 0:
print("No links on CID, aborting: " + obj["Hash"])
if obj["Links"]["Name"] == "":
print("Not a directory: " + obj["Hash"])
for i in obj["Links"]:
req = requests.post(NODE+API+"files/cp?arg=/ipfs/%s&arg=%s/%s" % (i["Hash"], TEMP, i["Name"]))
if req.text != "":
# Parses directories to merge together
if len(sys.argv) < 3:
print("Usage: ipfs_merge_dir.py <dir1> <dir2> [dir3 dir4...]")
cids = sys.argv[2:]
out = sys.argv
for i in cids:
out += "&arg="+i
# Main program
if __name__ == "__main__":
cids = parseFlags()
this is a very needed feature , didn’t you ask them to include it in the IPFS ?
If this is something people commonly want to do often, I could open an issue and see what the devs think about it .