locked
How does "My "Documents work in VB10-Win7? RRS feed

  • Question

  • To all the smart and fine people out here:

    In the simple program below using VB10 and Windows 7, I display in TextBox1 all the directories and files that exist in a path listed by the user in TextBox2. Simple enough. But, when trying to list all directories and files in the the following path (in textbox2) (my userName is Philippe):

    C:\Users\Philippe\My Documents

    I get the following message: Access to the path C:\Users\Philippe\My Documents  is denied. Make sure you have sufficient privileges to access this resources.   So my question is: I do I get these sufficient privileges ???????????????

    But then, note that if I type as a path:   C:\Users\Philippe\Documents , then everything works fine and the listing is correct, and includes also by the way all the hidden directories and files. But something strange happens: the listing includes a "My Music" directory and another "Music" directory. So my second question is: Why is that? Why two different names for the same thing?  Thanks in advance to anyone willing to help.                                           

    ----------------------------- Listing ----------------------------------------------------------------------------

    Imports System.IO
    Public Class Form1
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            TextBox1.Clear()
            Dim Path As String = TextBox2.Text
            Dim mydirs() As String = Directory.GetDirectories(Path)
            Dim dirlist As String
            For Each dirlist In mydirs
                TextBox1.AppendText(dirlist & vbCrLf)
            Next
            Dim myfiles() As String = Directory.GetFiles(Path)
            TextBox1.AppendText("--------------------" & vbCrLf)
            Dim filelist As String
            For Each filelist In myfiles
                TextBox1.AppendText(filelist & vbCrLf)
            Next
        End Sub
    End Class


    Philippe de Marchin

    Thursday, April 25, 2013 5:52 PM

Answers

  • My Documents is what is referred to as an NTFS "junction point" that points to a physical file folder (Documents in this case). You cannot access a junction point using file system operations.

    To get the underlying file system path it's best to use GetFolderPath and the SpecialFolder enumeration:

    http://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx


    Paul ~~~~ Microsoft MVP (Visual Basic)

    Thursday, April 25, 2013 6:04 PM
  • Hello,

    I can not test this, see if this will work.

    System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

    • Marked as answer by BigBuzzard Thursday, April 25, 2013 9:20 PM
    Thursday, April 25, 2013 5:57 PM

All replies

  • Hello,

    I can not test this, see if this will work.

    System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

    • Marked as answer by BigBuzzard Thursday, April 25, 2013 9:20 PM
    Thursday, April 25, 2013 5:57 PM
  • My Documents is what is referred to as an NTFS "junction point" that points to a physical file folder (Documents in this case). You cannot access a junction point using file system operations.

    To get the underlying file system path it's best to use GetFolderPath and the SpecialFolder enumeration:

    http://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx


    Paul ~~~~ Microsoft MVP (Visual Basic)

    Thursday, April 25, 2013 6:04 PM
  • Your explanation about NTFS junction points was very helpful. Thanks for the reference. This was totally new to me. I am simply going to parse the user input for the string "My " and eliminate it. I tried it and it seems to work well.    I shall try the GetFolderPath method too, Thanks again sincerely.  Big Buzzard.


    Philippe de Marchin

    Thursday, April 25, 2013 9:14 PM