Solved

My Documents Path

Posted on 2002-05-02
7
261 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
  • 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now