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

Fseek giving file size = 0 3

Status
Not open for further replies.

shangrilla

Programmer
Nov 21, 2001
360
US
The file(file name and path is stored in unarcfile) has data in it, but the file size is still being shown as o. What could be wrong?

If NOT (unarcfile == '')
Store FOPEN(unarcfile) TO file_handle && Open the file
Store FSEEK(file_handle, 0, 2) TO ifp_size && Move pointer to EOF
Store FSEEK(file_handle, 0) TO ifp_top && Move pointer to BOF
wait window str(ifp_size)
If ifp_size <= 0 && Is File empty?
Wait WINDOW 'This file is empty!' NOWAIT
Else
** load file
endif
endif
 
While I modified it a bit, it seems to work for me!
Code:
If NOT EMPTY(unarcfile)
  file_handle = FOPEN(unarcfile)      && Open the file
  ifp_size = FSEEK(file_handle, 0, 2) && Move pointer to EOF
  ifp_top = FSEEK(file_handle, 0)     && Move pointer to BOF
wait window str(ifp_size)
  If ifp_size <= 0                    && Is File empty?
    Wait WINDOW 'This file is empty!' NOWAIT
  Else 
    ** load file
  endif  
ENDIF
Rick
 
I still don't understand what is FSEEK() has to do with finding the file size??????????
The functions can return this info are
FSIZE() with the right setting (Read the help)
Or
ADIR()

Am I missing some thing?! Walid Magd
Engwam@Hotmail.com
 
unarcfile = ' '
unarcfile = &quot;c:\myapp\0523022225.835&quot;
If NOT EMPTY(unarcfile)
file_handle = FOPEN(unarcfile) && Open the file
*ifp_size = fsize(unarcfile)&&Fseek(file_handle, 0, 2) && Move pointer to EOF
ifp_size = Fseek(file_handle, 0, 2) && Move pointer to EOF
ifp_top = FSEEK(file_handle, 0) && Move pointer to BOF
Store '' TO l_string
disstr=&quot;Loading &quot; +unarcfile
wait window (disstr)
wait window str(ifp_size)
=fclose(file_handle)
endif

I tried walid's suggestion too, but i am still getting 0 as the file size for some files that have data in them.
 
Did you read the help for FSIZE() to get the right setting?? Walid Magd
Engwam@Hotmail.com
 
shangrilla

What sort of file is &quot;c:\myapp\0523022225.835&quot;?

The FSIZE() function is not a member of the low level file function family, whereas its name would suggest it is.

FSIZE() is specific to tables and not to files in general.

Why not, as Walid suggested use ADIR()

ADIR(laTemp,[c:\myapp\0523022225.835])
? laTemp[2] HTH

Chris [pc2]
 
On and off I am getting an error saying latemp.prg doesn't exist.
 
If c:\myapp\0523022225.835 is a &quot;temp&quot; file that hasn't been closed by the creating program, then all of these techniques are problematic - the OS may not be able to &quot;see&quot; it.
You'll get the &quot;latemp.prg doesn't exist&quot; error, if ADIR() doesn't create the array latemp[] - VFP thinks it's a function call. If you add:
[red]DIMENSION laTemp[1] [/red]
ADIR(laTemp,[c:\myapp\0523022225.835])
? laTemp[2]

This should fix this problem. Although the following is even better:
lnFileCount = ADIR(laTemp,[c:\myapp\0523022225.835])
IF lnFileCount < 1
? &quot;File not found&quot;
ELSE
? laTemp[2]
ENDIF

Rick


 
shangrilla

I suspect laTemp[2] is going out of scope, so you could use

PUBLIC ARRAY laTemp[1,5]

If you do so, you need to

RELE laTemp

at some point in your app.

Alternatively, you could add a form property as an array, and resolve it that way. When the form is closed, MYFORM.aTemp[1,5], will be destroyed with the form. HTH

Chris [pc2]
 
shangrilla

Rick could well be right - I assumed, (always dangerous), that c:\myapp\0523022225.835 exists at the time that the line of code incorporating ADIR() is used.

I also assumed you were calling laTemp elsewhere in your app, hence the post concerning, &quot;out of scope&quot;.

If c:\myapp\0523022225.835 does not exist, then the error message indicates that ADIR() is returning a value of 0, or in other words, no such file exists. HTH

Chris [pc2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top