Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

filecopy fails. Any ideas?

Status
Not open for further replies.

parig

Programmer
Feb 8, 2003
6
0
0
AU
Whats wrong with this?

dim strsourcefile as string,newfile as string
dim j as int

strsourcefile = "d:\apps\doc\benefitquote.xls"
newfile ="c:\benefitquote0.xls"

filecopy strsourcefile,newfile

j = 1

do while err>0
err =0
newfile = "c:\benefitquote"+trim(Str(j))+".xls"
filecopy strsourcefile,newfile
j= j+1
loop

I always get error number 52 -> Bad file name or number
i have checked that the file "d:\apps\doc\benefitquote.xls" exists. However, the new file "C:\benefitquote0.xls" is not creted

Any suggestions?


 
Err is never greater than zero. Try some other technique for you do loop.

 
no,Err can be greater than zero. In my case Err = 52 [Bad File Name or number]

 
First,
Code:
dim j as int
is a syntax error. You must spell "integer." Fix syntax errors first, then execute.

Second, technically Err is an object: 52 is the value of the Err.Number property. Reset it using Err.Clear, not by assigning zero.
 
yeah i have declared j as integer not int.
but the above code works fine for doc files
??


 
I don't know what your problem is. I ran this code on my machine and it works fine. Make sure that the problem lies here. Initially i thought the naming convention of this file is too long. You can shorten it if you like and check if it works, but I doubt it.
 
If all you want to do is loop though a directory's files and copy them all to another directory have a look at the Dir() function.

It would be something like this then:

Dim strFile As String

strFile = Dir("d:\apps\doc\benefitquote*.xls", vbArchive Or vbNormal Or vbReadOnly)

While Len(strFile) > 0
FileCopy "d:\apps\doc\" & strFile, "d:\" & strFile

strFile = Dir
Wend

Greetings,
Rick
 
LazyMe,

Apparently what he's trying to do is to continuously retry the file copy until there is no error. This isn't going to work, though, because there's no code (at least none included here) to handle run-time errors.

This could still go on indefinitely, as parig is attempting again and again to copy to the root directory of his C: drive. No more root directory entries available? Drive full? Your guess is as good as mine. We're not going to know until we get the exact story.

So here's three words:
-debug
-single step
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top