×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Fseek giving file size = 0
3

Fseek giving file size = 0

Fseek giving file size = 0

(OP)
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                               

RE: Fseek giving file size = 0

While I modified it a bit, it seems to work for me!

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

RE: Fseek giving file size = 0

2
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

RE: Fseek giving file size = 0

(OP)
unarcfile = ' '
unarcfile = "c:\myapp\0523022225.835"
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="Loading " +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.

RE: Fseek giving file size = 0

Did you read the help for FSIZE() to get the right setting??

Walid Magd
Engwam@Hotmail.com

RE: Fseek giving file size = 0

shangrilla

What sort of file is "c:\myapp\0523022225.835"?

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

RE: Fseek giving file size = 0

(OP)
On and off I am getting an error saying latemp.prg doesn't exist.

RE: Fseek giving file size = 0

If c:\myapp\0523022225.835 is a "temp" file that hasn't been closed by the creating program, then all of these techniques are problematic - the OS may not be able to "see" it.
You'll get the "latemp.prg doesn't exist" error, if ADIR() doesn't create the array latemp[] - VFP thinks it's a function call. If you add:
DIMENSION laTemp[1]
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
   ? "File not found"
ELSE
   ? laTemp[2]
ENDIF

Rick


RE: Fseek giving file size = 0

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

RE: Fseek giving file size = 0

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, "out of scope".

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close