Discussion:
MakeSureDirectoryPathExists API
(too old to reply)
arno
2006-02-20 23:12:36 UTC
Permalink
Hi,

I have a project in which I use a call to MakeSureDirectoryPathExists
WinAPI function. This function resides in imagehlp.dll, but also in
dbghelp.dll. As I understand it, MS advises to use the one from
dbghelp.dll. However, imagehlp.dll is distributed with IE 4 and up,
whereas dbghelp.dll is only included in Win2k and higher. So it seems
to me that if I want to be as generic as possible in terms of
user-base (notably the odd win98 user in my case), I should use the
one from imagehlp.dll

FYI: I am not too familiar with distributing apps, so I am simply
seeking advice.

How should I best go about: use and distribute dbghelp.dll with my app
or not? I use win2k to develop on, so when i include it in my
installer (i us the package & deployment wizard included with VB6), I
get a warning on XP systems that a newer version of dbghelp is
present. However, when I dont, my app will likely fail on Win98,
right?
Or should I simply use imagehlp and 'hope' that all my users have at
least IE4 installed (a pretty safe bet in my case)

What do you guys consider 'best practice'?

tia,
arno
Ken Halter
2006-02-20 23:28:11 UTC
Permalink
Post by arno
Hi,
I have a project in which I use a call to MakeSureDirectoryPathExists
WinAPI function. This function resides in imagehlp.dll, but also in
dbghelp.dll. As I understand it, MS advises to use the one from
dbghelp.dll. However, imagehlp.dll is distributed with IE 4 and up,
whereas dbghelp.dll is only included in Win2k and higher. So it seems
to me that if I want to be as generic as possible in terms of
user-base (notably the odd win98 user in my case), I should use the
one from imagehlp.dll
FYI: I am not too familiar with distributing apps, so I am simply
seeking advice.
How should I best go about: use and distribute dbghelp.dll with my app
or not? I use win2k to develop on, so when i include it in my
installer (i us the package & deployment wizard included with VB6), I
get a warning on XP systems that a newer version of dbghelp is
present. However, when I dont, my app will likely fail on Win98,
right?
Or should I simply use imagehlp and 'hope' that all my users have at
least IE4 installed (a pretty safe bet in my case)
What do you guys consider 'best practice'?
tia,
arno
Not sure about 'best practice' but.... imo, use imagehlp. If the system's so
old that IE4's not installed, it has other issues.

Check the contents of the following file... if it's not there, you can't
package it unless you're absolutely sure you have license to do so
(dbghelp's not in the list) and you're not shipping OS specific versions of
DLLs.

C:\Program Files\Microsoft Visual Studio\REDIST.TXT

Note that neither API is actually required. You can use a "VB Only" version
if you want. I can clean mine a bit and post if interested.
--
Ken Halter - MS-MVP-VB - Please keep all discussions in the groups..
DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm
Freeware 4 color Gradient Frame? http://www.vbsight.com/GradFrameCTL.htm
arno
2006-02-21 00:30:52 UTC
Permalink
Ken,

ta for the input.

I'd be *very* interested in a 'no-API' version. Have struggled with
lots of code examples using CreateDirectory API, but somehow I cant
get them quite right.

FYI: the app I am trying to create has a string value (as in: anything
goes, from a 3rd party-app), as a possiible path. There is no way
around that for me.

I have code in place to check for validity of the path, but the actual
creating (and error handling) is a challenge for me.

arno


On Mon, 20 Feb 2006 15:28:11 -0800, "Ken Halter"
Post by Ken Halter
Not sure about 'best practice' but.... imo, use imagehlp. If the system's so
old that IE4's not installed, it has other issues.
Check the contents of the following file... if it's not there, you can't
package it unless you're absolutely sure you have license to do so
(dbghelp's not in the list) and you're not shipping OS specific versions of
DLLs.
C:\Program Files\Microsoft Visual Studio\REDIST.TXT
Note that neither API is actually required. You can use a "VB Only" version
if you want. I can clean mine a bit and post if interested.
Randy Birch
2006-02-21 00:34:52 UTC
Permalink
Use the example at http://vbnet.mvps.org/code/file/nested.htm, and change
the CreateDirectory call to VB's MkDir instead. The difference with
CreateDirectory and MakeSureDirectoryPathExists is the later can create a
nested hierarchy of folders in one call, whereas CreateDirectory and MkDir
can only make one level per call.
--
Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/

Please reply to the newsgroups so all can participate.




"arno" <***@xs4all.nl> wrote in message news:***@4ax.com...
: Ken,
:
: ta for the input.
:
: I'd be *very* interested in a 'no-API' version. Have struggled with
: lots of code examples using CreateDirectory API, but somehow I cant
: get them quite right.
:
: FYI: the app I am trying to create has a string value (as in: anything
: goes, from a 3rd party-app), as a possiible path. There is no way
: around that for me.
:
: I have code in place to check for validity of the path, but the actual
: creating (and error handling) is a challenge for me.
:
: arno
:
:
: On Mon, 20 Feb 2006 15:28:11 -0800, "Ken Halter"
: <***@Use_Sparingly_Hotmail.com> wrote:
:
: >Not sure about 'best practice' but.... imo, use imagehlp. If the system's
so
: >old that IE4's not installed, it has other issues.
: >
: >Check the contents of the following file... if it's not there, you can't
: >package it unless you're absolutely sure you have license to do so
: >(dbghelp's not in the list) and you're not shipping OS specific versions
of
: >DLLs.
: >
: >C:\Program Files\Microsoft Visual Studio\REDIST.TXT
: >
: >Note that neither API is actually required. You can use a "VB Only"
version
: >if you want. I can clean mine a bit and post if interested.
:
Ken Halter
2006-02-21 15:22:40 UTC
Permalink
Post by arno
Ken,
ta for the input.
I'd be *very* interested in a 'no-API' version. Have struggled with
lots of code examples using CreateDirectory API, but somehow I cant
get them quite right.
FYI: the app I am trying to create has a string value (as in: anything
goes, from a 3rd party-app), as a possiible path. There is no way
around that for me.
I have code in place to check for validity of the path, but the actual
creating (and error handling) is a challenge for me.
arno
Here's what I have.... similar to Randy's code. It's not written to allow
UNC paths though (in case you need that as well)
'==========
Option Explicit

Private Sub Command1_Click()
If VBCreatePath("C:\Temp\Any\Thing\You\Want") = True Then
Debug.Print "VB Success!"
End If
End Sub

Private Function VBCreatePath(NewPath As String) As Boolean
Dim vArr As Variant
Dim sPath As String
Dim sCurrent As String
Dim iFor As Integer

On Error GoTo ErrorTrap

'Remove any trailing backslash (get ready to Split below)
sPath = NewPath
If Right$(sPath, 1) = "\" Then
sPath = Left$(sPath, Len(sPath) - 1)
End If

'Split the path into an array
vArr = Split(sPath, "\")

'Create the folder(s)
For iFor = 0 To UBound(vArr)
sCurrent = sCurrent & vArr(iFor) & "\"
If Not PathExists(sCurrent) Then
MkDir sCurrent
End If
Next iFor

'If it got this far with no errors, all's well.
VBCreatePath = True

Terminate:
Exit Function

ErrorTrap:
Debug.Print Err.Number, Err.Description
Debug.Assert False 'stops here in the IDE
Resume Terminate
End Function

Private Function PathExists(PathName As String) As Boolean
On Error Resume Next
If Len(PathName) > 0 Then
PathExists = ((GetAttr(PathName) And vbDirectory) > 0)
Err.Clear
End If
End Function
'==========
--
Ken Halter - MS-MVP-VB - Please keep all discussions in the groups..
DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm
Freeware 4 color Gradient Frame? http://www.vbsight.com/GradFrameCTL.htm
arno
2006-02-21 21:54:24 UTC
Permalink
Ken, Randy,

tx for the info. The mvps example is similar to the thre one ive
struggled with and eventually given up. This one looks a tad simpler
tho. What got me into trouble earlier was that it is actually very
common that users use UNC paths, so I will have to make some
modifications to it.

kind regards,
arno

Loading...