Finding an open directory is legal—it is public information indexed by a search engine. However, the data found within those directories often violates privacy laws like the GDPR or the Computer Fraud and Abuse Act (CFAA).
Add Disallow: /private-folder/ to your robots.txt file to tell search engines not to crawl those areas. intitle index of private
If you manage a website, you should ensure your "private" files stay that way. Here is how to prevent your directories from appearing in these search results: Finding an open directory is legal—it is public
Never rely on "security through obscurity." If a file is private, it should be behind a login screen or encrypted. intitle index of private
To understand the search, you have to understand how web servers work.