|
-
Nov 10th, 2000, 12:14 PM
#1
Thread Starter
Member
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!!!
-
Nov 10th, 2000, 01:03 PM
#2
Fanatic Member
...
First:
Try FileCopy in a staightforward way
FileCopy "c:\.....", "d:\..."
does it do it?
If yes, check your loop and
list..
let us know
-
Nov 10th, 2000, 02:19 PM
#3
Thread Starter
Member
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
-
Nov 10th, 2000, 02:25 PM
#4
Frenzied Member
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.
-
Nov 10th, 2000, 02:26 PM
#5
Fanatic Member
You can use the Dir function to iterate through all the files in a directory.
-
Nov 10th, 2000, 02:30 PM
#6
Fanatic Member
-
Nov 10th, 2000, 02:33 PM
#7
Fanatic Member
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
-
Nov 10th, 2000, 02:44 PM
#8
Fanatic Member
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.
-
Nov 10th, 2000, 02:44 PM
#9
Fanatic Member
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
-
Nov 15th, 2000, 02:24 PM
#10
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|