robjohnston
asked on
My Documents Path
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.shel l")
MyDocuments = mWindowsScriptingObject.Re gRead("HKE Y_CURRENT_ USER\" & _
"Software\Microsoft\Window s\CurrentV ersion\Exp lorer\Shel l Folders\Personal")
Set mWindowsScriptingObject = Nothing
End Property
This may not work on win 2000 (I haven't tried it).
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.shel
MyDocuments = mWindowsScriptingObject.Re
"Software\Microsoft\Window
Set mWindowsScriptingObject = Nothing
End Property
This may not work on win 2000 (I haven't tried it).
Sorry, left this part out:
Private mWindowsScriptingObject As Object
Private mWindowsScriptingObject As Object
Looks good on Win2K, bob_online:
Private Sub Command1_Click()
On Error Resume Next
Dim mWindowsScriptingObject As Object
Set mWindowsScriptingObject = CreateObject("wscript.shel l")
MsgBox mWindowsScriptingObject.Re gRead("HKE Y_CURRENT_ USER\" & _
"Software\Microsoft\Window s\CurrentV ersion\Exp lorer\Shel l Folders\Personal")
Set mWindowsScriptingObject = Nothing
End Sub
Private Sub Command1_Click()
On Error Resume Next
Dim mWindowsScriptingObject As Object
Set mWindowsScriptingObject = CreateObject("wscript.shel
MsgBox mWindowsScriptingObject.Re
"Software\Microsoft\Window
Set mWindowsScriptingObject = Nothing
End Sub
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
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
ASKER
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.
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.
MyDocPath = Environ$("UserProfile" & "\My Documents")
For Win98, I think you can use this:
MyDocPath = "C:\My Documents"