Thanks for your inputs.
Printable View
Thanks for your inputs.
If your question is how to create a Folder in VB 6, then the answer would beIf your question is something else, please explain.Code:MkDir "C:\NewFolder"
Often I need to make sure the folder exists (if it doesn't then I need to make it)
What I do is
This way you are guaranteed that the folder will always be thereCode:On Error Resume Next
MkDir "C:\NewFolder"
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.Quote:
Originally Posted by George1111
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
Thanks for your response! Actually, I meant which dll is Mkdir defined in? Thanks for your inputs.
Quote:
Originally Posted by Shuja Ali
It's built-in as a command in VB6.
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).
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")
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
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
Yup, except I would declare and strongly type: "mypath" and "checkit". :D
:wave: :D
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