Results 1 to 9 of 9

Thread: Moving text files

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2001
    Posts
    44

    Question Moving text files

    Hi,

    I need to move a text file from a directory to another.

    I have the following code to do that:

    Sub Manip_Files()
    Dim fso As New FileSystemObject, fil1

    Set fil1 = fso.GetFile("c:\testfile.txt")
    fil1.Move ("c:\tmp\testfile.txt")
    End Sub

    It gives the error:
    compile error: user-defined type not defined.

    Does anybody know why?

    How can I do it?

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    To use the FileSystemObject you have to set a reference to the Microsoft Scripting Runtime.
    To set it pick Reference on the Project menu.

  3. #3
    IMHO it is also incredibly complex to use the FSO for something so simple. This seems faster, doesn't require another depedency, and is less code:
    VB Code:
    1. FileCopy "c:\testfile.txt", "c:\tmp\testfile.txt"
    2. Kill "c:\testfile.txt"

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Well you can actually use the Name statement as well.
    VB Code:
    1. Name "c:\testfile.txt" As "c:\tmp\testfile.txt"
    Best regards

  5. #5

    Thread Starter
    Member
    Join Date
    Mar 2001
    Posts
    44

    Smile

    Thanks a lot.

    With the reference it works.

  6. #6
    DaoK
    Guest
    It gives the error:
    compile error: user-defined type not defined.



    Have you add the Microsoft Scripting Runtime ?

  7. #7
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Originally posted by DaoK
    It gives the error:
    compile error: user-defined type not defined.



    Have you add the Microsoft Scripting Runtime ?
    why don't you read the earlier replies first?

  8. #8
    DaoK
    Guest
    Why are you frustrated becasue I have read all but not this one SORRY OH MY GOD this morning you have a feeling problem or waht ?

  9. #9
    Megatron
    Guest
    Please do not over react. I believe he meant for you to read his first post in this thread.

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