none
Documents vs My Documents in Windows 7

    Question

  • I have a long used script (Excel VBA) that I recently migrated from my old WIN XP computer to a newer WIN 7 computer.  The script justs lists the contents of a folder:

     

    Sub SimpleFileLister()
    Dim s As String, FileName As String
    Cells.Clear
    s = "C:\Users\James\My Documents\*.*"
    FileName = Dir(s)
    Do Until FileName = ""
        i = i + 1
        Cells(i, 1).Value = FileName
        FileName = Dir()
    Loop
    End Sub

    The script fails on my new machine.  I opened a CMD window and poked around with some CD commands manually.  I discovered that CMD thinks the folder is:

    C:\Users\James\Documents

    Using this in the script works.

     

    Why does Windows Explorer think the folder name is  My Documents  ? 


    gsnu201103
    Thursday, April 07, 2011 7:37 PM

Answers

  • In VB Script you can find the location of the "My Documents" folder with a Shell Constant:

    const iMyDocuments = 5
    Set oShell = CreateObject("Shell.Application")
    Set oFolder = oShell.NameSpace(iMyDocuments)
    WScript.Echo "Location of ""My Documents"" is " & oFolder.Self.Path

    See here for the full list of Shell Contants:
    http://msdn.microsoft.com/en-us/library/bb774096%28v=vs.85%29.aspx

    Thursday, April 07, 2011 8:56 PM
  • Thanks!

     

    So  My Documents  is just some kind of alias for the "real" folder??

    Does TechNet or MSDN have any reference material on this topic?

     

    Thanks again!


    gsnu201103

    Yes, My Documents is an alias.

    Check out the link I gave you.

    Thursday, April 07, 2011 11:09 PM

All replies

  • In VB Script you can find the location of the "My Documents" folder with a Shell Constant:

    const iMyDocuments = 5
    Set oShell = CreateObject("Shell.Application")
    Set oFolder = oShell.NameSpace(iMyDocuments)
    WScript.Echo "Location of ""My Documents"" is " & oFolder.Self.Path

    See here for the full list of Shell Contants:
    http://msdn.microsoft.com/en-us/library/bb774096%28v=vs.85%29.aspx

    Thursday, April 07, 2011 8:56 PM
  • Thanks!

     

    So  My Documents  is just some kind of alias for the "real" folder??

    Does TechNet or MSDN have any reference material on this topic?

     

    Thanks again!


    gsnu201103
    Thursday, April 07, 2011 10:56 PM
  • Thanks!

     

    So  My Documents  is just some kind of alias for the "real" folder??

    Does TechNet or MSDN have any reference material on this topic?

     

    Thanks again!


    gsnu201103

    Yes, My Documents is an alias.

    Check out the link I gave you.

    Thursday, April 07, 2011 11:09 PM