Getting the file names of files I pinned locally

I’d like to know what it is exactly that is pinned locally. this is obviously not possible with content that was pinned based on hash. but can I somehow retrieve the file names of content that was pinned via add from my hard drive?

1 Like

Welcome to the forum, @chaser :wave:

You can use the following command to get more information about a CID:

ipfs dag get [CID]

This will basically render the DAG of the CID.

Alternatively, you can visualise the DAG using (as long as the CID is retrievable).

The problem you might face when you add a single file to IPFS, is that the filename is not added to the dag. For example, the following CID, is of an image

ipfs dag get bafybeibml5uieyxa5tufngvg7fgwbkwvlsuntwbxgtskoqynbt7wlchmfm
# Returns

If you are interested in retaining the information about the filename in the dag, you can use the -w, --wrap-with-directory bool - Wrap files with a directory object. option which will add the filename to the DAG.

For example

ipfs add -w --cid-version=1

added bafkreihmhz6l4fjqp43cnhgsaw3oecsi2fcr47adirtt5g2g7ymommylea
added bafybeicq43ymchctaila64ifhxebkariywdbtiub7xnm5xldtsyhx5wawa

You get two CIDs returned, one for the file (just the binary representation without the filename) and one for the “folder” which contains a single file with the filename:

If you inspect the second CID, you get:

$ ipfs dag get bafybeicq43ymchctaila64ifhxebkariywdbtiub7xnm5xldtsyhx5wawa

Also, everything you add using ipfs add is automatically pinned to your local node.

Hope that helps!