|
-
Sep 8th, 2000, 04:11 AM
#1
Thread Starter
Addicted Member
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
-
Sep 8th, 2000, 04:38 AM
#2
Addicted Member
Hi,
It's simply:
Code:
MkDir "C:\winnt\Folder\Folder1"
Hope this helps
Shaun
Web/Application Developer
VB6 Ent (SP5), Win 2000,SQL Server 2000
-
Sep 8th, 2000, 04:50 AM
#3
Hyperactive Member
If I use
And then use it again, it shows me an error?
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?
-
Sep 8th, 2000, 04:57 AM
#4
Addicted Member
You could check to see if it exists first before you try to create it.
Code:
If Dir("C:\NewDir",vbDirectory) = "" Then
'Folder does not exist so create it
MkDir "C:\NewDir"
Else
Msgbox "Directory already exists!"
End If
Hope this helps
Shaun
Web/Application Developer
VB6 Ent (SP5), Win 2000,SQL Server 2000
-
Sep 8th, 2000, 06:10 AM
#5
Hyperactive Member
Yup.
Does the trick .
THANX
-
Sep 8th, 2000, 06:19 AM
#6
Thread Starter
Addicted Member
Hi guys
thanks for the help
I keep getting an error message for an Invalid outside Procedure when I try this:
Any ideas
Code:
Dim dirname As String, newdir As String
Dim f As String
dirname = "C:\Test\newFolder\"
newdir = dirname & "NEWDIR"
MkDir newdir
newdir = newdir + "\"
Is it possible to use MkDir in this manner??????
-
Sep 8th, 2000, 06:27 AM
#7
Addicted Member
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:
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
or place it in a function like:
Code:
Private Function MakeFolder(NewDir as String)
Dim dirname As String
dirname = "C:\Dev\"
NewDir = dirname & NewDir
MkDir NewDir
End Function
and then you could call this function like:
Code:
Private Sub Form_Load()
MakeFolder("NameOfNewDIR")
End Sub
Hope this helps
Shaun
Web/Application Developer
VB6 Ent (SP5), Win 2000,SQL Server 2000
-
Sep 8th, 2000, 06:28 AM
#8
Thread Starter
Addicted Member
-
Sep 8th, 2000, 07:03 AM
#9
Thread Starter
Addicted Member
Hopefully you may be able to help me again.
Thanks to you guys here's what I now have:
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
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.
Thanks a lot for your time, I really appreciate it
JK
-
Sep 8th, 2000, 07:14 AM
#10
Addicted Member
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:
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
Hopefully, this should work for you.
Hope this helps
Shaun
Web/Application Developer
VB6 Ent (SP5), Win 2000,SQL Server 2000
-
Sep 8th, 2000, 07:58 AM
#11
Thread Starter
Addicted Member
S@NSIS, I really appreciate the time you've taken
Take Care
Jk
-
Sep 8th, 2000, 11:00 AM
#12
Fanatic Member
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?
-
Sep 8th, 2000, 12:07 PM
#13
Addicted Member
Hi,
I'm not sure, but to do it properly use:
Code:
MkDir App.Path & "\New Folder"
Hope this helps
Shaun
Web/Application Developer
VB6 Ent (SP5), Win 2000,SQL Server 2000
-
Sep 8th, 2000, 02:03 PM
#14
Turn it into a Sub.
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")
App.Path will make it so that it's in your exe's directory.
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
|