home *** CD-ROM | disk | FTP | other *** search
- name move
- page 55,132
- title 'MOVE --- transfer file between subdirectories'
-
- ;
- ; MOVE --- rename and/or transfer file between subdirectories
- ; Requires PC-DOS or MS-DOS 2.0 or greater.
- ;
- ; Copyright (c) 1984 by Ray Duncan
- ;
- ; Used in the form:
- ;
- ; A>MOVE path\filespec1 path\filespec2
- ;
- ; For example, to move the file MYFILE.DAT from the root
- ; directory to the subdirectory \SUBX, you would enter:
- ;
- ; A>MOVE \MYFILE.DAT \SUBX\MYFILE.DAT
- ;
- ; Of course, the file itself is not really "moved", its
- ; name is just removed from one directory and inserted into
- ; another directory. Can't be used to move files between drives.
- ;
- ; To assemble, link, and convert this program into
- ; an EXE file, follow these steps:
- ;
- ; C>MASM MOVE;
- ; C>LINK MOVE;
- ;
-
- cr equ 0dh ;ASCII carriage return
- lf equ 0ah ;ASCII line feed
- blank equ 20h ;ASCII space code
- eom equ '$' ;end of string marker
-
-
- ; Here we define a dummy segment containing labels
- ; for the default file control block and the command tail buffer,
- ; so that the main program can access those locations.
- ;
- psp segment para public 'PSP'
-
- org 05ch
- fcb label byte ;default file control block
-
- org 080h
- command label byte ;default command buffer
-
- psp ends
-
-
- cseg segment para public 'CODE'
-
- assume cs:cseg,ds:psp,es:data,ss:stack
-
-
- move proc far ;entry point from PC-DOS
-
- push ds ;save DS:0000 for final
- xor ax,ax ;return to PC-DOS
- push ax
- mov ax,data ;make our data segment
- mov es,ax ;addressable via ES register.
- mov ah,30h ;check version of PC-DOS.
- int 21h
- cmp al,2
- jae move1 ;proceed, DOS 2.0 or greater.
- mov dx,offset msg3 ;DOS 1.x --- print error message
- mov ax,es ;and exit. First fix up DS register
- mov ds,ax ;so error message is addressable.
- jmp move4
-
- move1: mov cl,command ;get length of name
- mov ch,0
- push cx ;save length
- mov si,offset command+1 ; move from
- mov di,offset fname ; move to
- rep movsb ;transfer names
- mov ax,es ;now set DS register
- mov ds,ax
-
- assume ds:data
-
- mov di,offset fname ;scan for first name
- pop cx ;length of string
- mov al,blank ;skip leading blanks
- repz scasb
- jz move3 ;jump, it was all blanks
- mov dx,di ;DS:DX=start of old name
- dec dx
- repnz scasb ;scan to next blank.
- jcxz move3 ;no 2nd blank, so 2nd name missing
- ;ES:DI = start of new name
- mov byte ptr [di-1],0 ;make first name an ASCIIZ string
- mov ah,56h ;call rename function
- int 21h
- jc move2 ;jump, rename failed
- ret ; return to dos
-
- move2: mov dx,offset msg1
- jmp move4
-
- move3: mov dx,offset msg2 ;missing filename
-
- move4: mov ah,9 ;print the string whose address
- int 21h ;is in DX.
- ret ;then return to DOS.
-
- move endp
-
-
- cseg ends
-
-
- data segment para public 'DATA'
-
- fname db 80 dup (0)
-
- msg1 db cr,lf
- db 'Move failed.'
- db cr,lf,eom
-
- msg2 db cr,lf
- db 'Missing filename.'
- db cr,lf,eom
-
- msg3 db cr,lf
- db 'Requires DOS version 2 or greater.'
- db cr,lf,eom
-
- data ends
-
-
- stack segment para stack 'STACK'
- db 64 dup (?)
- stack ends
-
- end move