TCSCFA
TCSCFA

Reputation: 21

Unexpected directories with Environment.GetFolderPath(Environment.SpecialFolder.Personal)

I am using following to get path to 'My Documents' folder in Windows 7 and iterate through its directories:

Dim diri As New DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.Personal))
For Each diri In diri.GetDirectories
 MessageBox.Show(diri.Name)
Next

One of the message boxes I get is for a 'My Music' folder. I do not have that folder in the 'My Documents' folder.

Is this the expected behavior?

Upvotes: 2

Views: 498

Answers (2)

TCSCFA
TCSCFA

Reputation: 21

used the below to get non hidden directories

Dim diri As New DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.Personal))
For Each diri In diri.GetDirectories
 If(dir.Attributes = FileAttributes.Directory) Then 
   MessageBox.Show(diri.Name)
 End If
Next

Upvotes: 0

Hand-E-Food
Hand-E-Food

Reputation: 12794

Yes. There is a hidden link in the "Documents" folder named "My Music" that links to your "Music" folder. There are similar ones for "Pictures" and "Videos". These are used for backwards compatability with poorly produced Windows XP software that hardcoded the paths to these folder rather than use the system defined settings like you are.

To see all of these links, from the command prompt, type:

Dir /AL %UserProfile%\Documents

Upvotes: 3

Related Questions