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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Invalid path or file name during Copy to 1

Status
Not open for further replies.

Eliott

Programmer
Nov 8, 2009
91
BA
I have a free table in VFP9 that I wish to export into text file. I used simply syntax for this move and more than 100 times it worked well, even in moment when file does exist I got warning "File does exist, do you want to overwrite? Yes/No" and suddenly this warning disappeared and I start to receive error "Invalid path or file name" each time if the file with same name already exist in folder; if I delete the file before Copy statement all worked fine. What is point? Same part of code, on same disk and partition but in different folder worked OK (and still is working) but in this one won't!? Why!? I tried to put:
set safety off
sys(1104) &&empty cache by force
select 1
use table1
copy to extable.txt delimited with ';'
close data
but nothing helped. I even closed few time VFP but still error remained. Probably destination file remained open or some app locked it? Can you please help me? Thank you.

There is no good nor evil, just decisions and consequences.
 
You probably need to 'handle' the error a little.

I'm assuming that it is the 'copy to' line that is throwing the error - not the 'use table1' line!

I would check for the existence of the file first, and delete it before copying out:

You could use something like this:

Code:
set safety off
sys(1104) &&empty cache by force
select 1
use table1
if file("extable.txt")
  delete file ("extable.txt")
endif
if !file("extable.txt")
  copy to extable.txt delimited with ';'
endif
close data


Personally, I would be a bit more specific:
Code:
set safety off
sys(1104) &&empty cache by force
select 1
use table1
if file("c:\myfolder\extable.txt")
  delete file ("c:\myfolder\extable.txt")
endif
if !file("c:\mytable\extable.txt")
  copy to ("c:\mytable\extable.txt") delimited with ';'
endif
close data

I would perhaps go a bit further, because the inbuilt file() function is easily confused and use a udf:

Code:
set safety off
sys(1104) &&empty cache by force
select 1
use table1
if Myfile("c:\myfolder\extable.txt")
  delete file ("c:\myfolder\extable.txt")
endif
if !Myfile("c:\mytable\extable.txt")
  copy to ("c:\mytable\extable.txt") delimited with ';'
endif
close data

FUNCTION MYFILE
	PARAMETER m.FILENAME
	PRIVATE m.FILENAME,m.FLG
	M.FLG = .F.
	IF !EMPTY(m.FILENAME)
		IF ADIR(TMPDIRFILES,m.FILENAME) > 0
			M.FLG = .T.
		ENDIF
	ENDIF
	RETURN(m.FLG)

I would also use an error handler just before the deletion, to allow for failure...

Even something like this offers up a million opportunities!

Code:
set safety off
sys(1104) &&empty cache by force
select 1
use table1
on error do fileerr
if Myfile("c:\myfolder\extable.txt")
  delete file ("c:\myfolder\extable.txt")
endif
if !Myfile("c:\mytable\extable.txt")
  copy to ("c:\mytable\extable.txt") delimited with ';'
endif
close data

FUNCTION MYFILE
	PARAMETER m.FILENAME
	PRIVATE m.FILENAME,m.FLG
	M.FLG = .F.
	IF !EMPTY(m.FILENAME)
		IF ADIR(TMPDIRFILES,m.FILENAME) > 0
			M.FLG = .T.
		ENDIF
	ENDIF
	RETURN(m.FLG)

PROCEDURE FILEERR
	RETURN



Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
Hi Griff,
thank you a lot for very well described possible solutions. It's definitive sure that some of these solution will work for me, just its' strange that sometime this issue appeared and sometime not. Simply, can't guess what is source of such VFP behavior, like some WinXP-process lock file, even nothing is visible in Who Lock Me? program... I checked error and code is 202 ("Invalid path...") When I changed the name of destination file I was able to execute same program many time w/o problem... strange. After I deleted file with "problematic name" program worked few time with this name and again started reporting same old error... Can't find out why, so...
Well, I'll adopt some of your solution and cross my fingers that this was all of VFP surprise for me in this month ;)
Thank you again.

There is no good nor evil, just decisions and consequences.
 
Good luck

I think something has the file open.

Or perhaps there is an odd character in the path...

come back if you need more help.

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
I tried today "old scheme" with classic approach described in my first post: again problem with it. When I changed name of destination file the process is running fine few time and again same thing. Probably is some kind of locked file or remained opened, even there is no warning "File does exist, do you want to overwrite"!!! It could be some kind of WinXP "joke" definitive, the funniest thing is that this form and program are working nice in other folder on same PC, same partition! Well, who said that programming under Win is boring stuff!? ;) Thank you Griff for your effort to help me.

There is no good nor evil, just decisions and consequences.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top