'Any method to detect which folders in C:\Users I can't access

I make a program in Windows 10 to collect all file list in my disk, and it should be run in system privilege.

But for personal folder, e.g. login as other user's account, I think I should avoid scanning their folders.

The user's personal folder is unser C:\Users usually. But how to detect which folder I can access? Or which one I cann't?

Below is my C:\Users folder and I can access all those folders. But if a new guy login on my Windows and create a new account, e.g. jack2. Then a new folder named jack2 should be shown there and I should not show any file in the C:\Users\jack2 when I run the program.

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source