-
Hello everyone,
I was wondering if anyone can show me how to create a new folder and copy an existing file into the new folder using vb code. Basically, I want the function to create a new folder called "Test" in "C:\project" and copy a file called "Textfile.txt" into "C:\project\Textfile". Thank you!
Marci Sarwan ([email protected])
P.S. I would really appreciate it if you can please provide
some sample code along with the explanation. Thanks!
-
Here you go:
Code:
If Dir("C:\project\Test", vbDirectory) <> "" Then
MkDir "C:\project\Test"
FileCopy "Textfile.txt", "C:\project\Textfile"
End If
-
Hello Matthew,
how do I copy the Textfile.txt into the desired directory as a different name. Can I do it like this?
FileCopy "Textfile.txt", "C:\project\Another_Name.txt"
Thanks!
Marci
-
-
And Also...
You can also do this:
Code:
Dim Name As String
Dim Name2 As String
Name2 = InputBox("Enter a folder:","Copy To...")
Name = "C:\Project\" & Name2
If Dir(Name,vbDirectory) <> "" Then
MkDir name
FileCopy "Textfile.txt", Name
End If
Nice one, isn't it?
[Edited by Asaf_99 on 10-04-2000 at 04:48 PM]
-
Asaf_99, can you use Name? Name is to rename a file. I think you have to use a different variable. I may be wrong though :rolleyes:.