Click here to Login

directory operations(masm)



; 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 'Dir Operations:',0dh,0ah,
                '1.Create  2.Delete  3.Quit$'
        choice db 'Choice: $'
        msgDir db 0dh,0ah,'Dir: $'
        invOp db 'Invalid Option!$'
        path db 50 dup(0)              
        msg_ok db 0dh,0ah,'Operation Successfull!$'
        msg_fail db 0dh,0ah,'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 CREATEDIR
        cmp al, 02h
        je DELETEDIR
        cmp al, 03h
        je FINISH
        print nl
        print invOp
        jmp ENTERCHOICE

        CREATEDIR:
        print msgDir
        mov si, offset path
        call readString
        mov dx, offset path
        mov ah, 39h     ;Interrupt to create dir
        int 21h
        jmp CHECKERROR

        DELETEDIR:
        print msgDir
        mov si, offset path
        call readString
        mov dx, offset path
        mov ah, 3Ah     ;Interrupt to delete dir
        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>dir_op
Dir Operations:
1.Create  2.Delete  3.Quit
Choice: 1
Dir: SAMPLEDIR
Operation Successfull!
Choice: 2
Dir: SAMPLEDIR
Operation Successfull!
Choice: 1
Dir: FOLDER
Operation Successfull!
Choice: 1
Dir: FOLDER
Operation Failed!
Choice: 3

**************************



0 comments:

Post a Comment