Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2004
    Bangalore, India

    Unanswered: Copy Files Using VB


    my application uses VB 6.0. i'd like to take back ups of word files created using my app. the prob i face is, the Embedded spaces in the path names.

    i cannot use Shell to copy files due to the embedded spaces in the pathname.

    Shell ("Copy D:\My App Path\Docs\sample.doc
    E:\My Back Up Folder\")
    generates an error "File Not Found"

    i hope this has to do with the Embedded space in my path name
    is ther ne other way of doing this other than using "Shell" ?

    i do welcome any easier / faster methods for taking back ups of my Doc files

    pl help

    thanks in advance



  2. #2
    Join Date
    Mar 2004
    Make a reference to the Microsoft Scripting Runtime and then use the CopyFile Method. Here are the details:

    Scripting Runtime Library

    CopyFile Method
    Copies one or more files from one location to another.

    object.CopyFile ( source, destination[, overwrite] )
    Required. The object is always the name of a FileSystemObject.
    Required. Character string file specification, which can include wildcard characters, for one or more files to be copied.
    Required. Character string destination where the file or files from source are to be copied. Wildcard characters are not allowed.
    Optional. Boolean value that indicates if existing files are to be overwritten. If true, files are overwritten; if false, they are not. The default is true. Note that CopyFile will fail if destination has the read-only attribute set, regardless of the value of overwrite.
    Wildcard characters can only be used in the last path component of the source argument. For example, you can use:

    fso = new ActiveXObject("Scripting.FileSystemObject");
    fso.CopyFile ("c:\\mydocuments\\letters\\*.doc", "c:\\tempfolder\\")
    FileSystemObject.CopyFile "c:\mydocuments\letters\*.doc", "c:\tempfolder\"
    But you cannot use:

    fso = new ActiveXObject("Scripting.FileSystemObject");
    fso.CopyFile ("c:\\mydocuments\\*\\R1???97.xls", "c:\\tempfolder")
    FileSystemObject.CopyFile "c:\mydocuments\*\R1???97.xls", "c:\tempfolder"
    If source contains wildcard characters or destination ends with a path separator (\), it is assumed that destination is an existing folder in which to copy matching files. Otherwise, destination is assumed to be the name of a file to create. In either case, three things can happen when an individual file is copied.

    If destination does not exist, source gets copied. This is the usual case.
    If destination is an existing file, an error occurs if overwrite is false. Otherwise, an attempt is made to copy source over the existing file.
    If destination is a directory, an error occurs.
    An error also occurs if a source using wildcard characters doesn't match any files. The CopyFile method stops on the first error it encounters. No attempt is made to roll back or undo any changes made before an error occurs.

    Download for FREE the ADO/DAO Data Controls that makes life EASIER developing database applications in: VB, FoxPro, Access, VC++, .NET etc... Navigate, Add New, Delete, Update, Search, Undo and Save your changes. Supports Disconnected Recordsets and Transactions!

    Or try our Ask An Expert service to answer any of your questions!

Posting Permissions

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