At his moment I have 2 methods in my mind.
method 1) Open the file, move to the end of it by using AX=4202h INT 21h and the file size will be at DX:AX if no error occured.
INT 21h, function 42 (move file pointer of an open file)AH = 42hAL = 0 (move from beggining of file) or 1 (move from currect possition of file) or 2 (move from the end of file)BX = File handleCX:DX = number of bytes to move.
example:
; open the fileMOV AX,3D02hMOV DX,OFFSET FileNameINT 21h
; Save handle in BXMOV BX,AX
;Move at the end of the fileMOV AX,4202hXOR CX,CX ;XOR DX,DX ;Zero bytes from the end of fileINT 21h
; now CX:DX contanis file length.
; close fileMOV AH,3EhINT 21h
FileName: db 'file1.tmp',0
Method 2) By using find first function and then getting the filesize from the DTA.the DTA is located at CS:0080h, but if we want to change it's location ,we can do it by using function 1Ah of INT 21h.
FUNCTION 1Ah (Set DTA) of INT 21hAH = 1AhDS:DX = New location of DTA (Disk Transfer Area)
FUNCTION 4Eh (Find first matching file) of INT 21hAH = 4EhCX = Attributes OF file to search (I thing this matters only if you are searching for volume label, so in any other situatoin use 3Fh for CX)DS:DX = pointer to the filename or file mask.
and now the DTA formatoffset 15h attrubute of file (byte)16h File time (word)18h file date (word)1Ah file size (dword)1Eh name of file found
Example:; in this example we will take the default DTA adress, although it's a good idea to change the DTA adress in general
MOV AH,4EhMOV CX,03FhMOV DX,OFFSET FileMaskINT 21h
MOV DX,WORD PTR [80h + 1Ah] ; Remember 80h is the default DTA adressMOV CX,WORD PTR [80h + 1Ah + 2]
;now CX:DX contains the file size
Hope I helped/AndreasURL:http://users.otenet.gr/k/katsiapi/hapiflou
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
At his moment I have 2 methods in my mind.
method 1) Open the file, move to the end of it by using AX=4202h INT 21h and the file size will be at DX:AX if no error occured.
INT 21h, function 42 (move file pointer of an open file)
AH = 42h
AL = 0 (move from beggining of file) or 1 (move from currect possition of file) or 2 (move from the end of file)
BX = File handle
CX:DX = number of bytes to move.
example:
; open the file
MOV AX,3D02h
MOV DX,OFFSET FileName
INT 21h
; Save handle in BX
MOV BX,AX
;Move at the end of the file
MOV AX,4202h
XOR CX,CX ;
XOR DX,DX ;Zero bytes from the end of file
INT 21h
; now CX:DX contanis file length.
; close file
MOV AH,3Eh
INT 21h
FileName: db 'file1.tmp',0
Method 2) By using find first function and then getting the filesize from the DTA.
the DTA is located at CS:0080h, but if we want to change it's location ,we can do it by using function 1Ah of INT 21h.
FUNCTION 1Ah (Set DTA) of INT 21h
AH = 1Ah
DS:DX = New location of DTA (Disk Transfer Area)
FUNCTION 4Eh (Find first matching file) of INT 21h
AH = 4Eh
CX = Attributes OF file to search (I thing this matters only if you are searching for volume label, so in any other situatoin use 3Fh for CX)
DS:DX = pointer to the filename or file mask.
and now the DTA format
offset 15h attrubute of file (byte)
16h File time (word)
18h file date (word)
1Ah file size (dword)
1Eh name of file found
Example:
; in this example we will take the default DTA adress, although it's a good idea to change the DTA adress in general
MOV AH,4Eh
MOV CX,03Fh
MOV DX,OFFSET FileMask
INT 21h
MOV DX,WORD PTR [80h + 1Ah] ; Remember 80h is the default DTA adress
MOV CX,WORD PTR [80h + 1Ah + 2]
;now CX:DX contains the file size
Hope I helped
/Andreas
URL:http://users.otenet.gr/k/katsiapi/hapiflou