Is there a way to retrieve the filesize of a file using the FINDOPEN command, or any other way within Ebasic without actually opening the file and using a LEN command?
Thanks,
Michael
Try:
Private Declare Function GetFileSize Lib "kernel32" (ByVal hFile As Long, lpFileSizeHigh As Long) As Long
Bill
That would be the same as using LEN on the file variable, which calls the GetFileSize API function.
The only way to do it without opening the file first is the API function GetFileAttributesEx:
http://msdn2.microsoft.com/en-us/library/aa364946.aspx
Paul.
I tried that getfilesize but I still must be doing something wrong. I will upload a code sample in a bit. Thanks for the help. I think my problems are actually with the declare import.
You can lead a horse to water.....
type FILETIME
UINT64 qwTime
end type
type WIN32_FILE_ATTRIBUTE_DATA
UINT dwFileAttributes
FILETIME ftCreationTime
FILETIME ftLastAccessTime
FILETIME ftLastWriteTime
UINT nFileSizeHigh
UINT nFileSizeLow
end type
WIN32_FILE_ATTRIBUTE_DATA dat
declare import,GetFileAttributesExA(filename as string,info_level as int,dat as pointer),int
GetFileAttributesExA("c:\\autoexec.bat",0,dat)
int64 size
size = dat.nFileSizeHigh
size = size << 32
size |= dat.nFileSizeLow
PRINT "Size of file = ",size
do:until inkey$ <> ""
And if you had a copy of the ibasic offline forums
http://www.ionicwind.com/forums/index.php/topic,1464.msg14167.html#msg14167
You would have found this gem, which shows both how to recursively print all files in a directory AND get their file sizes without having to open the file ;)
type FILETIME
DEF dwLowDateTime as UINT
DEF dwHighDateTime as UINT
ENDTYPE
TYPE WIN32_FILE_ATTRIBUTE_DATA
DEF dwFileAttributes as UINT
DEF ftCreationTime as FILETIME
DEF ftLastAccessTime as FILETIME
DEF ftLastWriteTime as FILETIME
DEF nFileSizeHigh as UINT
DEF nFileSizeLow as UINT
ENDTYPE
WIN32_FILE_ATTRIBUTE_DATA wad
DECLARE IMPORT,GetFileAttributesExA(filename as STRING,infoenum as INT,lpData as POINTER),INT
DEF count:INT
OPENCONSOLE
'recursively print all directories
count = printdir("d:\\")
PRINT count,"Files"
PRINT "Press Any Key"
DO:UNTIL INKEY$ <> ""
CLOSECONSOLE
END
SUB printdir(path:STRING),INT
DEF count:INT
DEF dir,attrib:INT
DEF filename:STRING
DEF fullname:STRING
count = 0
dir = FINDOPEN(path + "*.*")
IF(dir)
DO
filename = FINDNEXT(dir,attrib)
IF len(filename)
IF attrib & @FILE_DIRECTORY
IF(filename <> ".") & (filename <> "..")
PRINT path + "[" + filename + "]"
fullname = path + filename + "\\"
count = count + printdir(fullname)
ENDIF
ELSE
count = count + 1
PRINT path + filename,
'get the file size
GetFileAttributesExA(path+filename,0,wad)
PRINT str$((wad.nFileSizeHigh << 32) | wad.nFileSizeLow)
ENDIF
ENDIF
'the exit case is when there are no more entries
'in the current directory
UNTIL filename = ""
FINDCLOSE dir
ENDIF
RETURN count
ENDSUB