Solved

My Documents Path

Posted on 2002-05-02
7
267 Views
Last Modified: 2010-05-02
Hi folks.

I'm writting a little backup program which will get certian files from the "My Document" folder.

The program will be for Win98 and Win2K.

Is the an easy way of finding the path to "My Documents". Is it anything like app.path?

Thanks, Rob.
0
Comment
Question by:robjohnston
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 22

Expert Comment

by:rspahitz
ID: 6986467
For Win2000, you can use this:

MyDocPath = Environ$("UserProfile" & "\My Documents")

For Win98, I think you can use this:

MyDocPath = "C:\My Documents"

0
 
LVL 28

Accepted Solution

by:
AzraSound earned 50 total points
ID: 6986551
"Using SHGetFolderPath to Find Popular Shell Folders"
http://www.mvps.org/vbnet/index.html?code/browse/csidl.htm
0
 
LVL 5

Expert Comment

by:bob_online
ID: 6986832
You know, the user can rename "My Documents" to anything they want...

This method will find "My Documents" no matter what it is called:

Public Property Get MyDocuments() As String

   On Error Resume Next
   
   Set mWindowsScriptingObject = CreateObject("wscript.shell")
   MyDocuments = mWindowsScriptingObject.RegRead("HKEY_CURRENT_USER\" & _
      "Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Personal")

   Set mWindowsScriptingObject = Nothing

End Property


This may not work on win 2000  (I haven't tried it).
0
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
LVL 5

Expert Comment

by:bob_online
ID: 6986921
Sorry, left this part out:

   Private mWindowsScriptingObject     As Object
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6986980
Looks good on Win2K, bob_online:

Private Sub Command1_Click()

  On Error Resume Next
  Dim mWindowsScriptingObject As Object
 
  Set mWindowsScriptingObject = CreateObject("wscript.shell")
  MsgBox mWindowsScriptingObject.RegRead("HKEY_CURRENT_USER\" & _
     "Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Personal")

  Set mWindowsScriptingObject = Nothing

End Sub
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 6987065
Now you have to worry about the user having the latest scripting engine installed (for use of the wscript.shell class)...I would stick to the API method I linked to above.  If it seems too complicated, here is the stripped down version:



Option Explicit

Private Declare Function SHGetFolderPath Lib "shfolder" Alias "SHGetFolderPathA" (ByVal hwndOwner As Long, ByVal nFolder As Long, ByVal hToken As Long, ByVal dwReserved As Long, ByVal lpszPath As String) As Long
Private Const CSIDL_PERSONAL As Long = &H5


Private Sub Command1_Click()
    Dim strPath As String
 
    'fill pidl with the specified folder item
    strPath = Space$(260)
   
   If SHGetFolderPath(Me.hWnd, CSIDL_PERSONAL, 0&, &H0, strPath) = 0 Then
       MsgBox Left$(strPath, InStr(strPath, Chr$(0)) - 1)
   End If
End Sub
0
 
LVL 1

Author Comment

by:robjohnston
ID: 6989054
Thanks to everyone.

I have chosen AzraSound's solution as it fits the bill the best and gives me an easy way of backing up over user info. The program will only run on Win98SE and Win2k so there aren't any worries there.

Cheers, Rob.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month10 days, 4 hours left to enroll

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question