home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PROGRAMS / UTILS / DOS_HELP / ADVMSDOS.ZIP / MOVE.ASM < prev    next >
Encoding:
Assembly Source File  |  1986-06-19  |  4.3 KB  |  139 lines

  1.         name    move
  2.         page    55,132
  3.         title   'MOVE --- transfer file between subdirectories'
  4.  
  5. ;
  6. ; MOVE --- rename and/or transfer file between subdirectories
  7. ; Requires PC-DOS or MS-DOS 2.0 or greater.
  8. ;
  9. ; Copyright (c) 1984 by Ray Duncan
  10. ;
  11. ; Used in the form:
  12. ;
  13. ;       A>MOVE path\filespec1 path\filespec2 
  14. ; For example, to move the file MYFILE.DAT from the root 
  15. ; directory to the subdirectory  \SUBX, you would enter:
  16. ;
  17. ;       A>MOVE  \MYFILE.DAT  \SUBX\MYFILE.DAT
  18. ;
  19. ; Of course, the file itself is not really "moved", its 
  20. ; name is just removed from one directory and inserted into
  21. ; another directory.  Can't be used to move files between drives.
  22. ;
  23. ; To assemble, link, and convert this program into 
  24. ; an EXE file, follow these steps:
  25. ;
  26. ;    C>MASM MOVE;
  27. ;     C>LINK MOVE;
  28. ;
  29.  
  30. cr      equ     0dh             ;ASCII carriage return
  31. lf      equ     0ah             ;ASCII line feed
  32. blank   equ     20h             ;ASCII space code
  33. eom     equ     '$'             ;end of string marker
  34.  
  35.  
  36. ; Here we define a dummy segment containing labels
  37. ; for the default file control block and the command tail buffer,
  38. ; so that the main program can access those locations.
  39. ;
  40. psp     segment para public 'PSP'  
  41.  
  42.         org     05ch
  43. fcb     label   byte            ;default file control block
  44.  
  45.         org     080h
  46. command label   byte            ;default command buffer
  47.  
  48. psp     ends
  49.  
  50.  
  51. cseg    segment para public 'CODE'
  52.  
  53.         assume  cs:cseg,ds:psp,es:data,ss:stack
  54.  
  55.  
  56. move    proc    far             ;entry point from PC-DOS
  57.  
  58.         push    ds              ;save DS:0000 for final
  59.         xor     ax,ax           ;return to PC-DOS
  60.         push    ax
  61.         mov     ax,data         ;make our data segment
  62.         mov     es,ax           ;addressable via ES register.
  63.         mov     ah,30h          ;check version of PC-DOS.       
  64.         int     21h
  65.         cmp     al,2
  66.         jae     move1           ;proceed, DOS 2.0 or greater.
  67.         mov     dx,offset msg3  ;DOS 1.x --- print error message
  68.         mov     ax,es           ;and exit. First fix up DS register 
  69.         mov     ds,ax           ;so error message is addressable.
  70.         jmp     move4
  71.  
  72. move1:  mov     cl,command      ;get length of name
  73.         mov     ch,0
  74.         push    cx              ;save length
  75.         mov     si,offset command+1  ; move from
  76.         mov     di,offset fname      ; move to
  77.         rep movsb               ;transfer names
  78.         mov     ax,es           ;now set DS register
  79.         mov     ds,ax   
  80.  
  81.     assume     ds:data
  82.  
  83.         mov     di,offset fname ;scan for first name
  84.         pop     cx              ;length of string
  85.         mov     al,blank        ;skip leading blanks
  86.         repz scasb      
  87.         jz      move3           ;jump, it was all blanks
  88.         mov     dx,di           ;DS:DX=start of old name
  89.         dec     dx
  90.         repnz scasb             ;scan to next blank.
  91.         jcxz    move3           ;no 2nd blank, so 2nd name missing
  92.                                 ;ES:DI = start of new name
  93.         mov     byte ptr [di-1],0 ;make first name an ASCIIZ string
  94.         mov     ah,56h          ;call rename function
  95.         int     21h             
  96.         jc      move2           ;jump, rename failed
  97.         ret                     ; return to dos
  98.  
  99. move2:  mov     dx,offset msg1
  100.         jmp     move4
  101.  
  102. move3:  mov     dx,offset msg2  ;missing filename
  103.  
  104. move4:  mov     ah,9            ;print the string whose address
  105.         int     21h             ;is in DX.
  106.         ret                     ;then return to DOS.
  107.  
  108. move    endp
  109.  
  110.  
  111. cseg    ends
  112.  
  113.  
  114. data    segment para public 'DATA'
  115.  
  116. fname           db      80 dup (0)
  117.  
  118. msg1            db      cr,lf
  119.                 db      'Move failed.'
  120.                 db      cr,lf,eom
  121.  
  122. msg2            db      cr,lf
  123.                 db      'Missing filename.'
  124.                 db      cr,lf,eom
  125.  
  126. msg3            db      cr,lf
  127.                 db      'Requires DOS version 2 or greater.'
  128.                 db      cr,lf,eom
  129.  
  130. data    ends    
  131.  
  132.  
  133. stack   segment para stack 'STACK'
  134.         db      64 dup (?)
  135. stack   ends
  136.  
  137.         end     move
  138.