Results 1 to 10 of 10

Thread: HELP!!! Using FileCopy, having problems

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2000
    Location
    Midwest
    Posts
    35

    Exclamation

    I have written the following code to copy a file from one location to another:

    For counter2 = 1 To List2.SelCount
    Select Case List2.Selected(txtListItem2)
    Case 1
    FileCopy txtFileSource, txtFileDest

    Case 0
    MsgBox ("Will not be copied")
    End Select

    Next counter2

    I am having trouble with the FileCopy command, it keeps returning an error '75' message the path/file access error.

    HELP, PLEASE!!!

  2. #2
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    617

    ...

    First:
    Try FileCopy in a staightforward way

    FileCopy "c:\.....", "d:\..."

    does it do it?

    If yes, check your loop and
    list..

    let us know

  3. #3

    Thread Starter
    Member
    Join Date
    Sep 2000
    Location
    Midwest
    Posts
    35

    Question still having problems

    I am pulling files from various drives and adding them to a filelistbox, then the files are selected and copied to another location. The comes in when I use the FILECOPY statement to copy the files from the filelistbox to the new location. The full subroutine is shown below:

    Private Sub CopyFiles()
    Dim txtListItem2 As Integer
    Dim counter2 As Integer
    Dim txtFileDest As String
    Dim txtFileSource As String
    Dim intCopyFlag As Long


    txtFileSource = List2.List(List2.ListIndex)
    txtFileDest = "c:\newfiles\"
    txtListItem2 = List2.ListIndex


    For counter2 = 1 To List2.SelCount
    Select Case List2.Selected(txtListItem2)
    Case 1
    FileCopy txtFileSource, txtFileDest

    Case 0
    MsgBox ("Will not be copied")
    End Select

    Next counter2

    End Sub

  4. #4
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    It's because you do
    txtFileDest = "c:\newfiles\"

    you need to pass it the filename to:

    txtFileDest = "c:\newfiles\MYFILE.EXT"



    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  5. #5
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715
    You can use the Dir function to iterate through all the files in a directory.
    Oetje
    oetje@home.nl
    93606776
    Visual Basic 6, Windows 2000

    Never pet a burning dog

  6. #6
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715
    Oetje
    oetje@home.nl
    93606776
    Visual Basic 6, Windows 2000

    Never pet a burning dog

  7. #7
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    736
    If your listbox contains the full path of the file to copy, and you need to copy the file to a new folder, keeping the same file, try using the FileSystemObject to add the filename to the destination.

    For example, if the listbox contains c:\testfile.txt, txtFileDest will contain c:\newfiles\testfile.txt.

    Good luck !

    Code:
    Private Sub CopyFiles()
        Dim txtListItem2 As Integer
        Dim counter2 As Integer
        Dim txtFileDest As String
        Dim txtFileSource As String
        Dim intCopyFlag As Long
        Dim fso As Object
        Set fso = CreateObject("Scripting.FileSystemObject")
    
        
        txtFileSource = List2.List(List2.ListIndex)
        txtFileDest = "c:\newfiles\"
        txtListItem2 = List2.ListIndex
        
        For counter2 = 1 To List2.SelCount
        
            Select Case List2.Selected(txtListItem2)
            Case 1
                txtFileDest = txtFileDest & fso.GetFileName(txtFileSource)
                FileCopy txtFileSource, txtFileDest
            Case 0
                MsgBox ("Will not be copied")
            End Select
        
        Next counter2
    
        Set fso = Nothing
    End Sub

  8. #8
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    736
    What the heck. If you use the above with the FileSystemObject, you can use this code.

    Code:
            Case 1
                fso.copyfile txtFileSource, txtFileDest, True
    The copyfile takes care of carrying over the name of the file for you.

  9. #9
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633
    Agree with Jop on this one!

    Filecopy "C:\Hello.txt", "C:\Hello2.txt"

    [Edited by Nitro on 11-10-2000 at 02:46 PM]
    Chemically Formulated As:
    Dr. Nitro

  10. #10

    Thread Starter
    Member
    Join Date
    Sep 2000
    Location
    Midwest
    Posts
    35

    Exclamation A big thanks

    I want to thank everyone who contributed to my search about FileCopy. A very big thank you to jbart. IT WORK!!!

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