Click to See Complete Forum and Search --> : file handling program


ezzikkel
March 4th, 2006, 11:06 PM
hi guys i'm a newbie here, hope you can help me with my program...


i need to mke a n assembly program that opens,close,and delete's a certain file...


thanks in advance!

rxbagain
March 7th, 2006, 03:56 PM
You can use this as a reference in using functions Interrupt Services DOS, BIOS, EMS und Mouse (http://www.htl-steyr.ac.at/~morg/pcinfo/hardware/interrupts/inte1at0.htm). You can find the functions in openning, closing, and deleting files and lot more.

Hope it will help you

BytePtr
March 9th, 2006, 12:04 PM
There is nothing difficult with this stuff. Coz i love coding in ASM i created it for you. There is no error checking (eg: file exist or not, its read only or not).
It creates empty file to C:\, then ask you press any key, after each keypress it performs some operations: file creating, opening, closing and finally deleting.
Each operation is informed by message. Read comments to learn more. Hope it helps you. Feel free to ask if u dont understand something.
;*----------------------------------------------------------------------*
; PROJECT NAME: EXAMP *
; CREATED: 09.03.2006 *
; LAST MODIFIED: 09.03.2006 *
; AUTHOR: V.A aka BytePtr *
; PURPOSE: File creating, opening, closing and deleting *
; COMMENTS: Needs atleast TASM 3.x or MASM 6.x *
; Compiled & tested under TASM 3.01 *
;*----------------------------------------------------------------------*

.model small
.stack 200h
.data
fhandle dw ? ; to save handle of file

fname db "C:\SUPERFILE.SUP",0

fcreated db "FILE CREATED, press any key to open it...$"
fopened db "FILE OPENED, press any key to close it...$"
fclosed db "FILE CLOSED, press any key to delete it...$"
fdeleted db "FILE DELETED, press any key to quit...$"
.code
.startup

call CreateFile

call ClrScr
lea dx, fcreated
mov ah, 09h
int 21h

call WaitKey

call OpenFile

call ClrScr
lea dx, fopened
mov ah, 09h
int 21h

call WaitKey

call CloseFile

call ClrScr
lea dx, fclosed
mov ah, 09h
int 21h

call WaitKey

Call KillFile

call ClrScr
lea dx, fdeleted
mov ah, 09h
int 21h

call WaitKey

.exit

CreateFile proc near
xor cx, cx ; create ordinary file
mov ah, 3ch ; DOS createfile func
mov dx, offset fname ; filename to DS:DX
int 21h
mov fhandle, ax ; save file handle, we need it later
ret
CreateFile endp

OpenFile proc near
mov ah, 3dh ; DOS open file func
xor al, al ; read only, but its actually not important in this case
mov dx, offset fname ; filename to DS:DX
int 21h
ret
OpenFile endp

CloseFile proc near
mov ah, 3eh ; DOS close file func
mov bx, fhandle ; file handle to BX
int 21h
ret
CloseFile endp

KillFile proc near
lea dx, fname
mov ah, 41h ; DOS 41h func = delete file
int 21h
ret
KillFile endp

ClrScr proc near
mov ax, 03h ; clear screen by setting mode 80x25x16
int 10h ; do it
ret
ClrScr endp

WaitKey proc near
xor ax, ax ; clear AX
int 16h ; wait for keypress
ret
WaitKey endp
end

Tested under XP Pro, no problems found.

EDIT:In future try to work such apps by yourself, you will learn alot from it, believe me, i have experience in this area ;)