开发者

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开发者_Python百科. I do not have that folder in the 'My Documents' folder.

Is this the expected behavior?


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


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜