Solved

My Documents Path

Posted on 2002-05-02
7
266 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

734 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