Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

My Documents Path

Posted on 2002-05-02
7
Medium Priority
?
269 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 200 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
Technology Partners: 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!

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

721 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