; PROGRAM: OPERATIONS ON A FILE
print macro s
mov dx, offset s
mov ah, 09h
int 21h
endm
data segment
nl db 0dh,0ah,'$'
menu db 'File Operations:',0dh,0ah,
'1.Delete 2.Rename 3.Quit $'
choice db 'Choice: $'
msgFile db 0dh,0ah,'File: $'
msgNName db 'New Name: $'
invOp db 'Invalid Option!$'
path db 50 dup(0)
newn db 50 dup(0)
oldn db 50 dup(0)
msg_ok db 0dh,0ah,'File Operation Successfull!$'
msg_fail db 0dh,0ah,'File Operation Failed!$'
data ends
code segment
assume ds:data, cs:code
start:
mov ax, data
mov ds, ax
mov es, ax
print menu
ENTERCHOICE:
print nl
print choice
mov ah, 01h
int 21h
sub al, 30h
cmp al, 01h
je DELETEFILE
cmp al, 02h
je RENAMEFILE
cmp al, 03h
je FINISH
print nl
print invOp
jmp ENTERCHOICE
DELETEFILE:
print msgFile
mov si, offset path
call readString
mov dx, offset path
mov ah, 41h ;Interrupt to Delete File
int 21h
jmp CHECKERROR
RENAMEFILE:
print msgFile
mov si, offset oldn
call readString
print nl
print msgNName
mov si, offset newn
call readString
mov dx, offset oldn
mov di, offset newn
mov ah, 56h ;Interrupt to Rename
int 21h
CHECKERROR:
jc FAILED
print msg_ok
jmp ENTERCHOICE
FAILED:
print msg_fail
jmp ENTERCHOICE
FINISH:
mov ah, 4ch
int 21h
readString proc near
mov ah, 01h
READCHAR:
int 21h
cmp al, 0dh
je STRINGREAD
mov [si], al
inc si
jmp READCHAR
STRINGREAD:
;add a zero for file operations
mov [si], 00h
RET
readString endp
code ends
end start
**************************
OUTPUT
Z:\S5IT\masm>file_opnew
File Operations:
1.Delete 2.Rename 3.Quit
Choice: 1
File: test1.txt
File Operation Successfull!
Choice: 2
File: test2.txt
New Name: hello.txt
File Operation Successfull!
Choice: 4
Invalid Option!
Choice: 3
**************************
0 comments:
Post a Comment