|
-
April 18th, 2007, 09:51 AM
#1
How to declare Mkdir in vb?
-
April 18th, 2007, 09:58 AM
#2
Re: How to declare Mkdir in vb?
If your question is how to create a Folder in VB 6, then the answer would be
Code:
MkDir "C:\NewFolder"
If your question is something else, please explain.
-
April 19th, 2007, 03:41 AM
#3
Re: How to declare Mkdir in vb?
Often I need to make sure the folder exists (if it doesn't then I need to make it)
What I do is
Code:
On Error Resume Next
MkDir "C:\NewFolder"
This way you are guaranteed that the folder will always be there
-
April 19th, 2007, 05:55 AM
#4
Re: How to declare Mkdir in vb?
 Originally Posted by George1111
Often I need to make sure the folder exists (if it doesn't then I need to make it)
What I do is
Code:
On Error Resume Next
MkDir "C:\NewFolder"
This way you are guaranteed that the folder will always be there
What happens when there is some other error, say you do not have write permission or the drive is not readable. You are not trapping it with the above code and using the above code you will never know what error actually came. I would prefer checking for the existence of folder in a proper way rather than using the above method.
-
April 21st, 2007, 04:16 AM
#5
Re: How to declare Mkdir in vb?
Something like ..
Code:
If Dir("C:\MyFolder") = "" then
On Error Goto ErrorMakingFolder
MkDir("C:\MyFolder)
End If
'Carry on here as everthing is OK
Exit Sub
ErrorMakingFolder:
Msgbox "Error Making Folder 'MyFolder" - Perhaps your permissions etc are not ......etc etc.."
Exit sub
-
April 28th, 2007, 10:42 AM
#6
Re: How to declare Mkdir in vb?
Thanks for your response! Actually, I meant which dll is Mkdir defined in? Thanks for your inputs.
 Originally Posted by Shuja Ali
If your question is how to create a Folder in VB 6, then the answer would be
Code:
MkDir "C:\NewFolder"
If your question is something else, please explain.
-
April 28th, 2007, 12:44 PM
#7
Re: How to declare Mkdir in vb?
It's built-in as a command in VB6.
-
April 28th, 2007, 02:28 PM
#8
Re: How to declare Mkdir in vb?
Hello,
Just in case the question was not formulated as you meant to :
1) In VB, MKDir is not a function but a Statement
2) MKDir VB Statement is acting exactly the same way than the CreateDirectory function of the kernel32 Librfary of the Windows Api.
3) the CreateDirectory function returns a value geater than 0 if it succeeds.
If it fails, it returns 0 (and you can then use the GetLastError function to get more information upon the reason(s) for which it failed).
-
April 29th, 2007, 12:08 AM
#9
Re: How to declare Mkdir in vb?
Use Microsoft Scripting Runtime as reference.
Code:
Declare fso as new file system object.
if fso.folderexists("Name") =true 'where name is your folder name to be created. or checked
do something....
else
fso.createfolder("Name")
-
April 29th, 2007, 09:56 AM
#10
Re: How to declare Mkdir in vb?
Hello,
Why to make an appli heavier (declaring and using FSO) when VB does it fast and very simply !!!
Code:
Private Sub Command1_Click()
MsgBox IIf(Dir("d:\monoutila\", vbDirectory) <> "", "exists", "does not exist")
End Sub
-
April 29th, 2007, 10:04 AM
#11
Re: How to declare Mkdir in vb?
So that (for our friend's purpose) :
Code:
Private Sub Command1_Click()
mypath = "d:\monoutila"
checkit = IIf(Dir(mypath & "\", vbDirectory) <> "", True, False)
If Not checkit Then MkDir mypath
End Sub
-
April 29th, 2007, 10:16 AM
#12
Re: How to declare Mkdir in vb?
Yup, except I would declare and strongly type: "mypath" and "checkit".
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions 
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
-
April 29th, 2007, 10:21 AM
#13
Re: How to declare Mkdir in vb?
-
April 29th, 2007, 12:54 PM
#14
Re: How to declare Mkdir in vb?
I would recommend using the MakeSureDirectoryPathExists API. It doesn't throw errors if the folder exists and will create any subdirectories that need creating too:
Code:
Private Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" ( _
ByVal lpPath As String) As Long
Private Sub Command1_Click()
MakeSureDirectoryPathExists "C:\All\These\Folders\Are\Created\"
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|