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

Getting File Size in Bytes

Status
Not open for further replies.

Chris1000

Programmer
Jun 4, 2001
2
US
For a particular named file, I want to return the file size in bytes and store to a memory variable or perhaps drop it into a table.

Can anyone suggest how I get the file size - either through VFP or through DOS.

Thanks in advance for your help.
 
Try the adir() function:

cFilename = "c:\winnt\system32\vfp6run.exe)
if ADIR(arArrayName, &cFilename.) = 1
?ADIR(2)
ENDIF

the adir() function returns the # of files that match the criteria -- so may sample uses 1 as there had better only be one match!

see your help files for all the info that adir can tell you!

 
Depending on the type of file, you could FOPEN the file and STORE FSEEK into a memory variable.
 
Hi Chris

** cMyFile = MyFullPath+MyFile+FileExt
myFileBytes=IIF(ADIR(myDir,(cMyFile))=1,myDir(1,2),0)

? myFileBytes

Hope this helps you
ramani :-9
(Subramanian.G)
FoxAcc
ramani_g@yahoo.com
 
I believe the FSIZE() function would work as well. The ADIR() function is a better choice if you are going to be looking at multiple files within a specified directory. When using FSIZE() to find the filesize of a specified file, SET COMPATIBLE must be set to ON.

nSize = FSIZE(cFileName)
 
Just some small corrections on the code Marsh posted:
** Incorrect
cFilename = "c:\winnt\system32\vfp6run.exe)
if ADIR(arArrayName, &cFilename.) = 1
?ADIR(2)
ENDIF

** Good
cFilename = "c:\winnt\system32\vfp6run.exe"
if ADIR(arArrayName, cFilename) = 1
?arArrayName(2) && or more clearly arArrayName[1,2]
ENDIF

Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top