Why does file/ls <hash> not provide a filename for the hash, but does include filenames for any linked hashes?

Hello. I’m fairly new to IPFS and I’ve been toying with the API a bit. I’m currently trying to find a way build an index of everything on the IPFS network. So far I’ve been grabbing hashes by scraping the output of ipfs log tail and then doing a file/ls API query on the hash. This provides all the info I need about a specific hash EXCEPT for the filename of that hash. This is confusing me because if the hash is a directory all linked subfile names ARE included. Is there are reason for this or am I going about it the wrong way?