CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Copying a file.

  1. #1
    Join Date
    Mar 2001
    Posts
    6

    Copying a file.

    Can anyone tell me how to copy a file in visual basic. I want a file to be copied from a base directory to another directory, and the filename can be renamed. Can somone tell me how to do this or just how to copy it to another directory? Thanks!


  2. #2
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: Copying a file.

    From the Help Facility
    '
    '

    Visual Basic for Applications Reference
    '
    FileCopy Statement
    '
    '
    Copies a file.
    '
    Syntax
    '
    FileCopy source, destination
    '
    The FileCopy statement syntax has these named arguments:
    '
    Part Description
    '
    source Required.
    '
    String expression that specifies the name of the file to be copied. The source may include directory or folder, and drive.
    '
    destination Required.
    '
    String expression that specifies the target file name. The destination may include directory or folder, and drive.
    '
    '
    Remarks
    '
    If you try to use the FileCopy statement on a currently open file, an error occurs.


    --------------------------------------------------------------------------------
    Send feedback to MSDN.Look here for MSDN Online resources.


    John G

  3. #3
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Copying a file.

    Here are several examples how to copy a file

    1.faster than FileCopy
    'ref to MS scripting runtime
    Dim fso As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    fso.CopyFile "C:\openfile.txt", "C:\newfile.txt"

    2.only for closed file
    FileCopy "C:\OpenFile.txt", "C:\NewFile.txt"


    3.
    shell "start.exe type c:\finename.txt >> hjjkhkj"


    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

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

Featured