For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic > May 2005 > MkDir with blanks









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author MkDir with blanks
Bruno Köller

2005-05-29, 3:55 pm

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?


Benedikt Hübschen

2005-05-29, 3:55 pm

Private Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll"
(ByVal lpPath As String) As Long

MakeSureDirectoryPathExists "D:\AAA\BBB\CCC\DDD"


Douglas J. Steele

2005-05-29, 3:55 pm

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!)



"Bruno Köller" <mydevicenull@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?
>



Jim Carlock

2005-05-29, 3:55 pm

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" <mydevicenull@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?


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com