Sunday, August 2, 2009

MkDir and VB6

On vbCity there was a forum post about using VB6 to create a folder.

How do I create a FOLDER ONLY... ?

Sorry I have a bad memory of things, I know how to create the files in the folder but forgot how to create the FOLDER its self.. confused

Im using App.path to get to the point of the folder... App.path & "??????"


mike




Edited by - Malan on 7/25/2009 6:18:28 AM


Some help was had, but later there was this post:
thank you for Your Help .. it got me on the right Path.... BUT

This Worked MkDir App.Path & "\DataFiles\"

BUT

This Didnt Work : MkDir App.Path & "\Data Files\"

any suggestions of why ... ?

Adding the Space between the name isnt working ?

Mike


Now, I'm no VB6 expert, but I tinker around on the Windows command line all the time and I'd like to suggest a couple of things, but first I'll show the reasons why.

First off, for those who do not know, MKDIR is a command you can use on the Windows command line to make a new directory (folder).

Open a directory in Windows Explorer and a command prompt to the same directory. For our example we will be working in C:\test

On the command line type:
MKDIR C:\test\the longest folder name in XP history

and press return.

You should see seven new folders.

This is because Windows has treated each word in our folder name as its own parameter to pass to MKDIR.

To get around this and make a folder with spaces we need to pass the entire path, including drive letter, to MKDIR. This is done by wrapping the entire path in quotes.

Go ahead and type the previous command on the command line, but this time with quotes:
MKDIR "C:\test\the longest folder name in XP history"

The result is yet another folder with our hideous-long name.

So, the answer as to why has been given--- MKDIR processes each parameter separately and parameters with spaces should be fully wrapped in quotes. (Actually, you usually only need the closing quote if there's just one parameter. The closing quote is assumed by Windows. But I'm classing that as a Windows bug instead of a useful tip)

Now for practical solutions...
First, you may want to forget about spaces in paths altogether. I have and I am happier this way.

Second, I had problems with a previous VB6 application when I used app.path in this way, but once I assigned the value of app.path to a string variable and used that variable the problem went away. I don't know why, it just did.

Third, if you need quotes in your final string (for creating the folder in VB) you may find chr(int) useful.

I hope this is useable information for someone. If you have any corrections or added information, please let me know.


____________________________________________
This post brought to you by 1554 Enlightened Black Ale

No comments: