Results 1 to 6 of 6

Thread: Does anyone know how to create a new folder and copy a file into it??

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2000
    Location
    Posts
    52

    Unhappy

    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!
    Marci Sarwan

  2. #2
    Guest
    Here you go:

    Code:
    If Dir("C:\project\Test", vbDirectory) <> "" Then
    MkDir "C:\project\Test"
    FileCopy "Textfile.txt", "C:\project\Textfile"
    End If

  3. #3

    Thread Starter
    Member
    Join Date
    Jun 2000
    Location
    Posts
    52
    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
    Marci Sarwan

  4. #4
    Guest
    Yes!

  5. #5
    Hyperactive Member Asaf_99's Avatar
    Join Date
    Jul 2000
    Location
    Israel
    Posts
    335

    Talking 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 Sagi

    ICQ: 61917199
    E-Mail: [email protected]

  6. #6
    Guest
    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 .

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width