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

File Sizes

Status
Not open for further replies.

BJZeak

Programmer
May 3, 2008
230
CA
Been a long while since I did any programming in Foxpro ... I was recently given a 1M text file of raw data that needs to be parsed into a table ... I pulled out some of my old code and just created a short program to load this file only to hit a wall with the FOPEN command.

dim hFile as ulong
dim iRet as ulong

hFile = FOPEN("c:\tmp\file.txt",10)

iRet = FSEEK(hFile,0,0)

FOPEN is always returning -1 which indicates FOPEN isn't opening this file for some reason ... I suspect this is probably related to the size of the file? I created a simple 3 line text file and it opened fine so I know this code is working.

Is there anyway to get past this issue in VFP 9 under XP PRO SP3?


 
You can use FILETOSTR() to read in the entire file as a string. all in one gulp. That would avoid the awkwardness of low level FOPEN(), FSEEK(), FGETS(), etc. That way you could use the standard SUBSTR(), AT(), RAT() functions, among others.

Code:
IF FILE("c:\tmp\file.txt")  && Does file exist and user have rights to access it?
   *nHandle = FOPEN("c:\tmp\file.txt",10)  && ReadOnly, unbuffered
   nHandle = FOPEN("c:\tmp\file.txt",0)  && ReadOnly, buffered
   ? "File handle: "+LTRIM(STR(nHandle))
   FCLOSE(nHandle)  && Remember to close the file when done
ELSE
   ? "Unable to find table.  Check whether file exists or user rights"
ENDIF
 
1M what? 1MB?

If the file is really only 1MB, then size is not your issue. (For future reference, the file size limit is and always has been 2GB.)

More likely, you already have the file open in another app. Are you poking around in there with Notepad?

If nothing else, something like this should scoop the thing into a usable format:

Create Cursor MyImport (text M)
Insert Into MyImport (text) Values ( FileToStr("yourfile.txt") )

Then you have the entire file in a memo field you can slice and dice as needed. This might at least let you have a look-see to figure out what's really going on in there.
 
"I suspect this is probably related to the size of the file?"

No, I regularly use FOPEN() with LARGE files which are around 1.5 GB GB and do not have problems. I then follow it with FGETS() to acquire the data in a 'row' for parsing.

The FILETOSTR() method also works fine, but I find that for my needs of acquiring individual 'row' content, the FOPEN() & FGETS() works well.

Now it is true that I do not use the optional attribute with my FOPEN(), but as long as it has NOT been left open by some previous operation (VFP or other) and I have used the valid path + filename, the file opens (returns 1) just fine.

If you find that someone else has the file open which is preventing you to have access to it, you might want to consider working off of a COPY of the file instead of the original version.

Good Luck,
JRB-Bldr
 
Thank-you for all the feedback ... SIZE isn't the issue ... which is what I was stuck on ... The file was open but not by anything else ... the file was opened by VFP and didn't close properly so it wouldn't open it again.

I have an FClose(hFile) but because there were errors in my program I expect VFP left in limbo ... from the command line if I do a close all then the program runs

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top