Home > Enterprise >  C# Directory.GetDirectories() return inexisting directory
C# Directory.GetDirectories() return inexisting directory

Time:02-04

I want to use Directory.GetDirectories(path) and then working with sub-directories but, when I start running my app, VS return me System.UnauthorizedAccessException. I can understand I fix this, no problem. The real problem is, as you can see in the linked picture, code try to acces a folder that doesn't exist.

In windows explorer I show all hide files and folder, and as you can see (again) when I go to the right spot in my PC, "Ma Musique" doesn't exist (and never existed by the way).

Where is folder come from and how can I deal with this ?

enter image description here

EDIT :

Code try to access this directory just after Lumion directory. As you see above, "Ma Musique" doesn't exist.

enter image description here

CMD (as administrator) doesn't find it too. Directory.Exists() return true when give it "Ma musique" directory path.

CodePudding user response:

That is what is known as a "virtual" folder and it is there for backwards compatibility with old versions of Windows. When users got their own music/video/etc folders, they were all turned into system virtual folders that don't actually exist at all as they are aggregates of content in multiple folders. However programs that expect these folders to exist would break if they were missing so Windows would make a symbolic link that in some cases would allow a redirect. I don't remember for sure but i think the redirect only worked if you were running as administrator. In any case you can't browse into them as they aren't real.

CodePudding user response:

You are seeing "acces denied" and/or do get this Exception "System.UnauthorizedAccessException".

Microsoft has a tool ICACLS that displays or modifies discretionary access control lists (DACLs) on specified files, and applies stored DACLs to files in specified directories.

Because of the mentioned error, you should investigate the response of:

icacls "C:\Users\thoma\Documents\Ma musique"

(When you get an error about "Access denied", please execute this as Administrator)

The output of ICACLS should explain why you do no have access to that file/directory.

  • Related