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

Trouble using FILE()

Status
Not open for further replies.

crogec

Programmer
May 10, 2002
16
US
VFP5.0
I am trying to let the user select a file, using GETFILE, to copy to a floppy. I use PUTFILE() to allow the selection of the same OR different output filename. I am using low level file manipulation for the purpose of getting better control of the progress bar so the user doesn't sit there wondering if anything is really happening. Using FWRITE, the progress bar part works fine.
I use FILE() to determine if the file already exist on the destination drive. It is here I have the trouble. I have used the file() function many times with no trouble while working in a given directory. What I am doing different this time is trying to determine if the file exists in a different drive/directory; specifically does the file exist on the A drive floppy while working from a subdirectory on the C drive. The trouble is, if the filename exists anywhere, FILE() returns a .T. I even tried hard coding the path, IF FILE(A:\[filename]) and it always returns .T. even with a blank formatted floppy! I am using essentially the lines as found in the help file.

cFileNameIn = GETFILE('*','Read File Name','',0)
.
*Select the A drive and the same filename...
cFileOutName = PUTFILE('Write file name',cFileNameIn,cFileNameInExt)
*cFileOutName should now be something like "A:\[filename]"
.
.
IF FILE(cFileOutName) && Does file exist?
*Should fail this if floppy is blank...
gnTestFile = FOPEN(cFileOutName,12) && If so, open read/write
ELSE
gnTestFile = FCREATE(cFileOutName) && If not create it; READ/WRITE
ENDIF

It never fails the IF and returns a positive handle but of course fails to open a new file. It never gets to the FCREATE().

Now, if I CHANGE the name of the output file to something that I know does not exist anywhere, it WILL create the new file on the A drive and everything works fine.

It seems that without a name change, it remembers the original path and sticks to it no matter if I change it or not.

What am I missing here?
Thanks,
George
 
Hi George,

If the file name you are searching is otherwise available as included in your application, VFP will always return .t.

The way to go is..

IF ADIR(laFile,"A:cFile.EXT") > 0
** FILE EXISTS
ELSE
** FILE DOES NOT EXIST
ENDIF

:)


ramani :)
(Subramanian.G)
 
Thanks Ramani and Jim,
It seems that some days you are the windshield and some days you are the bug!

The substitution (&) worked fine Jim.

Ramani, I had to use the substitution in your idea as well and it works just fine.
Thanks again for your input.
George
 
Good to hear George. You know, I used to think I knew foxpro pretty well until I joined this group.

Jim Osieczonek
Delta Business Group, LLC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top