Sorry if it's a stupid question
But how do I make a folder called FOLDER1 inside a specified directory
eg. c:\winnt\Folder\Folder1.
How do I create the Folder1. I know that it's MkDir but I'm not really sure of the syntax
Printable View
Sorry if it's a stupid question
But how do I make a folder called FOLDER1 inside a specified directory
eg. c:\winnt\Folder\Folder1.
How do I create the Folder1. I know that it's MkDir but I'm not really sure of the syntax
Hi,
It's simply:
Hope this helpsCode:MkDir "C:\winnt\Folder\Folder1"
Shaun
If I use
And then use it again, it shows me an error?Code:MkDir "C:\NewDir"
How do I fix it so it can make the dir only the first time I activate my app and since then it won't show that error?
BTW, I want to keep the folder and not Kill it.
Any ideas?
You could check to see if it exists first before you try to create it.
Hope this helpsCode:If Dir("C:\NewDir",vbDirectory) = "" Then
'Folder does not exist so create it
MkDir "C:\NewDir"
Else
Msgbox "Directory already exists!"
End If
Shaun
Yup.
Does the trick :D.
THANX
Hi guys
thanks for the help
I keep getting an error message for an Invalid outside Procedure when I try this:
Any ideas
Is it possible to use MkDir in this manner??????Code:Dim dirname As String, newdir As String
Dim f As String
dirname = "C:\Test\newFolder\"
newdir = dirname & "NEWDIR"
MkDir newdir
newdir = newdir + "\"
Hi,
Your code works fine, it's just where you are placing it that is the problem. It needs to go into a sub or function which is why you are getting your error.
Try placing it in an event sub such as:
or place it in a function like:Code:'place a command button on your form
Private Sub Command1_Click()
Dim dirname As String, newdir As String
Dim f As String
dirname = "C:\Dev\"
newdir = dirname & "NEWDIR"
MkDir newdir
newdir = newdir + "\"
End Sub
'The code will run when you click Command1
and then you could call this function like:Code:Private Function MakeFolder(NewDir as String)
Dim dirname As String
dirname = "C:\Dev\"
NewDir = dirname & NewDir
MkDir NewDir
End Function
Hope this helpsCode:Private Sub Form_Load()
MakeFolder("NameOfNewDIR")
End Sub
Shaun
Cheers
Thanks a lot
Hopefully you may be able to help me again.
Thanks to you guys here's what I now have:
What I am trying to do now is put all files that are contained in the folder C:\TEST into the newly created folder C:\TEST\ArchiveFolder.Code:Private Function MakeFolder(NewDir As String)
Dim dirname As String
dirname = "C:\Test\"
NewDir = dirname & NewDir
MkDir NewDir
End Function
Private Function SearchForFileExt()
Dim findfiles As String
findfiles = Dir$(dirname & "*.jpg")
Do While findfiles <> ""
FileCopy dirname & findfiles, NewDir & findfiles
findfiles = Dir$
Loop
End Function
Private Sub Timer1_Timer()
If Dir("C:\Test\NewFolder", vbDirectory) = "" Then
MakeFolder ("ArchiveFolder")
Else
Call SearchForFileExt
End If
End Sub
Thanks a lot for your time, I really appreciate it
JK
Hi again!! ;)
Ok.. In your MakeFolder function, you have two variables, NewDir and dirname. These are only local to the function and so when you call the SearchForFileExt function, they dont hold any values unless you say so within that function. There are two ways around it. Either declare the variables in the declarations area of your code or give them values in the function you are using them in.
Example of the latter:
Hopefully, this should work for you.Code:
Private Function SearchForFileExt()
dim dirname as string 'you have to declare them here again
dim NewDir as string ' they are only local variables
dirname ="C:\Test\" 'set the values
NewDir = "Whateveryouwant" 'for both variables
Dim findfiles As String
findfiles = Dir$(dirname & "*.jpg")
Do While findfiles <> ""
FileCopy dirname & findfiles, NewDir & findfiles
findfiles = Dir$
Loop
End Function
Hope this helps
Shaun
S@NSIS, I really appreciate the time you've taken
Take Care
Jk
if I do a mkDir procedure like this:
Private Function MakeFolder()
mkDir "New Folder"
End Function
will it create the folder in my app directory?
Hi,
I'm not sure, but to do it properly use:
Hope this helpsCode:MkDir App.Path & "\New Folder"
Shaun
Turn it into a Sub.
App.Path will make it so that it's in your exe's directory.Code:Private Sub MakeFolder(folder)
If Dir(folder, vbDirectory) = "" Then
mkDir App.Path & "\" & folder
Else
Exit Sub
End If
End Sub
Usage:
Call MakeFolder("NewFolder")