Home All Groups Group Topic Archive Search About
Author
29 May 2005 1:19 PM
Bruno Köller
I played a little bit around to get a function which creates a complete
directory tree (subsequent directories) and not only one additional level,
so that I could make a call like 'MakeDir D:\AAA\BBB\CCC\DDD' which calls
subsequent MkDirs internally. It works fine as long as there are no embedded
blanks.

Now testing with some portions of the pathname having embedded blanks I
found that adding chr$(34) at the beginning and the end of the pathname
variable the MkDir command sometimes works and sometimes not: MkDir chr$(34)
& pathname & chr$(34).

I found that if there is no embedded blank chr$(34) will cause an error.
This is no big problem because it's easy to distingusih between pathnames
with or without blanks and to run MkDir without Chr$(34) if no blanks given.

But when there are one or more blanks I found no system till now - chr$(34)
will not always help. Sometimes the MkDir command worked as expected and
sometimes not. Did anyone else encounter this problem?

Author
29 May 2005 1:26 PM
Benedikt Hübschen
Private Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll"
(ByVal lpPath As String) As Long

MakeSureDirectoryPathExists "D:\AAA\BBB\CCC\DDD"
Are all your drivers up to date? click for free checkup

Author
29 May 2005 1:30 PM
Douglas J. Steele
Afraid I didn't bother testing with blanks, but check whether either of the
approaches Randy Birch outlines in
http://vbnet.mvps.org/code/file/nested.htm work for you.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)



Show quoteHide quote
"Bruno Köller" <mydevicen***@onlinehome.de> wrote in message
news:d7cfir$rk4$1@online.de...
>I played a little bit around to get a function which creates a complete
>directory tree (subsequent directories) and not only one additional level,
>so that I could make a call like 'MakeDir D:\AAA\BBB\CCC\DDD' which calls
>subsequent MkDirs internally. It works fine as long as there are no
>embedded blanks.
>
> Now testing with some portions of the pathname having embedded blanks I
> found that adding chr$(34) at the beginning and the end of the pathname
> variable the MkDir command sometimes works and sometimes not: MkDir
> chr$(34) & pathname & chr$(34).
>
> I found that if there is no embedded blank chr$(34) will cause an error.
> This is no big problem because it's easy to distingusih between pathnames
> with or without blanks and to run MkDir without Chr$(34) if no blanks
> given.
>
> But when there are one or more blanks I found no system till now -
> chr$(34) will not always help. Sometimes the MkDir command worked as
> expected and sometimes not. Did anyone else encounter this problem?
>
Author
29 May 2005 3:19 PM
Jim Carlock
I'd suggest using a function like the following to put things in
quotes:

Public Const vbQuote As String = """"

Public Function QQ(sToQuote As String, Optional sQC As String = vbQuote) As String
  QQ = sQC & sToQuote & sQC
End Function

That way it's impossible to forget a quote character. The only problem
then is if the path already has quote characters embedded...

'...
If Left$(sPath, 1) <> vbQuote Then
  sPath = QQ(sPath)
End If
MkDir sPath

The route you take is going to depend upon if you're explicitly
controlling the path or are allowing a user to type in a path.

Also, there are some characters that are not spaces that look
like spaces, if you're using cut and paste operations to do
what you're doing. That's something that might need to taken
in consideration if you're copying and pasting from HTML.

Hope that helps.

--
Jim Carlock
Please post replies to newsgroup.

"Bruno Köller" <mydevicen***@onlinehome.de> wrote:
I played a little bit around to get a function which creates a complete
directory tree (subsequent directories) and not only one additional level,
so that I could make a call like 'MakeDir D:\AAA\BBB\CCC\DDD' which calls
subsequent MkDirs internally. It works fine as long as there are no embedded
blanks.

Now testing with some portions of the pathname having embedded blanks I
found that adding chr$(34) at the beginning and the end of the pathname
variable the MkDir command sometimes works and sometimes not: MkDir chr$(34)
& pathname & chr$(34).

I found that if there is no embedded blank chr$(34) will cause an error.
This is no big problem because it's easy to distingusih between pathnames
with or without blanks and to run MkDir without Chr$(34) if no blanks given.

But when there are one or more blanks I found no system till now - chr$(34)
will not always help. Sometimes the MkDir command worked as expected and
sometimes not. Did anyone else encounter this problem?

Bookmark and Share