Hi i have a project,i want to move file from destination address to source address
How can i do it in assembly i am beginner assembly programmer??
Anynone has source code??
I don't actually know what functions the DOS MOVE command uses, so take this as a more or less educated guess. If the source and destination are on the same drive you should be able to use interrupt 21h function 56h, Rename File, to move the file. Basically, you would keep the file name the same and specify different paths. If the source and destination are on different drives, then AFAIK, as a minimum, you must:
Get the length of the source file (interrupt 21h function 4Eh, Find First File)
Allocate a buffer (interrupt 21h function 48h, Allocate Memory)
Open the source file (interrupt 21h function 3Dh, Open File with Handle)
Read the source file into the buffer (interrupt 21h function 3Fh, Read File or Device)
Close the source file (interrupt 21h function 3Eh, Close File with Handle)
Create the destination file (interrupt 21h function 5Bh, Create New File)
Write the contents of the buffer to the destination file (interrupt 21h function 40h, Write File or Device)
Close the destination file (interrupt 21h function 3Eh, Close File with Handle)
Delete the source file (interrupt 21h function 41h, Delete File)
Free the buffer (interrupt 21h function 49h, Free Allocated Memory)
You must check for errors after each function, and you should make sure that you delete the source file only after you have successfully written the contents of the buffer to the destination file.
Edit:
This would work only for files that will fit in the buffer. For larger files you would need to have both files open simultaneously while you copied the data in buffer-sized chunks.
DOS function 56h "rename" will let you move a file on the same volume e.g. C:\DIR1\FILE.TXT to C:\DIR2\FILE.TXT - it just writes a new directory entry. (In this
example I'm pretty sure that the destination path (C:\DIR2) has to exist).
But for a drive-to-drive move, you have to go through what MichaelW said, or another way:
Allocate a buffer (2k maybe)
Open the source file
Open the dest file
Read 2k from source
Write 2k to dest
...until bytesread<2k (indicates eof)
Close dest
Close source
if you get here with no errors then Delete source
Deallocate buffer
thanks but i am beginner level in assembly ::) can you send sample codes pm ??? or program source codes like this operation??
Define what you want to do in a bit more detail.
Quote from: cathlax on May 03, 2007, 11:18:23 PM
Hi i have a project,i want to move file from destination address to source address
Are you talking about moving a file on a disk? Your use of "address" suggests memory...
Here is some "seed code." I don't understand much of the code I have for this, but I'll help where I can.
Post what you have so far, and we'll go from there.
Andy
DECLARE: ; Messages, Storage Areas, Equates
PATH_FILE_LEN equ 128;
SOURCE_FILE db PATH_FILE_LEN dup (0)
TARGET_PATH db PATH_FILE_LEN dup (0)
SOURCE_END dw 0
TARGET_END dw 0
SOURCE_HANDLE dw 0
TARGET_HANDLE dw 0
SOURCE_DTA db 44 dup(0)
TARGET_DTA db 44 dup(0)
VALID_IN db 'abcdefghijklmnopqrstuvwxyz,;=',9
VALID_OUT db 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',4 dup(32)
VALID_NUM equ $ - VALID_OUT + 1
BLKSIZE dw 0
LAST_BLOCK db 0
EVENT_FLAG db 0
ERR_HEAD db 10,13,'BAC Error - $'
NO_PARMS db 13,10,13,10,9,9,'BAC Fast File Copy ',13,10
db 13,10,9,9,'BAC [source] [destination]',13,10,10
db 9,9,'Ex. BAC a:\impt.txt c:\anywhere $'
CODE_START: ; Parse command line into source & target parameters
mov si,80h ; PSP parameter byte count pointer
mov cl,[si] ; Move byte count to CL
xor ch,ch ; Zero CH
jcxz NO_PARMS_PASSED ; If CX is zero, there are no parameters
mov dx,cx ; Save byte count in dx
inc si ; Point to parameter area
mov di,si ; Copy SI to DI for cleanup routine
cld ; Set direction flag to forward