ripsaw8080 wrote:Ideally you would use REN when moving on the same drive, COPY and DELETE when moving to a different drive. REN is relatively fast, that's why you'd want to use it where possible.
Yes, you can copy Daum's collection of utility programs out of the Z: drive and use them in other builds.
I had actually thought about that while I was waking up. In MSDOS, if you are moving on the same drive, all it does is rewrite the directory entries, no actual copies are made. So a CMD_MOVE function would check first to see if the target was on the same drive, then either call the CMD_RENAME function or call the CMD_COPY followed by the CMD_DELETE functions. It seems to me that that would be the easiest way to do it. Of course there would be the validity checks, are you trying to move something to the same place, is the target valid, etc... Are you moving a directory, if so, add in the CMD_RMDIR command (if you moved to another drive, I think the CMD_RENAME functions already handles directories.) Is the directory nested (does it have sub directories as well.)
Because CMD_RENAME doesn't handle wildcards, you would also have to break it down into single file calls (if wildcards were used.) Alternately, and this will save processing time as well, you could just copy the appropriate code from the other functions over. The problem with using the functions in place is that a lot of the validity checks will be duplicated. CMD_MOVE has to check if it's the same drive or not, is the command legal, etc... Then if you pass a file off to CMD_RENAME or CMD_COPY then CMD_DELETE, all 3 will be doing what you already did all over again. So DOSBox will be checking if the command is valid 2 or 3 times for every file. Easier for the programmer, harder on the end user's system. Personally, I'd say just copy the code over, then edit as appropriate.
So, as I see it: Check if the command is even valid (exit with appropriate message if not,) Check if it's to the same drive (skip RENAME section if its not,) RENAME section - Using the code from CMD_COPY build a loop for the files (for when wild cards are used,) in that loop use the code from CMD_RENAME to move them (the code already handles directories & sub-directories,) all successful? End process. COPY/DELETE section (Skip point) - Now we have to get a little more creative. The copy command doesn't handle directories. It already has a loop in place for wildcards though. Strip out the part about concatenating files (would be ignored anyway as the validity check should have already eliminated the possibility.) Now, is the source a directory? If so, we have to build a directory structure at the destination, build a list the directory and all sub-directories from the lowest to the highest. Then the first loop with the directories, inside this loop is a loop for the files themselves - use the same loop from CMD_COPY with the file name *.* Adding in the CMD_DELETE code if the "copy" is successful (if the copy fails, send an error message and exit the MOVE function.) Each time the second loop finishes successfully, use the code from CMD_RMDIR to remove that directory (if there was a failure, again send a message and exit.) All successful. Send a success message and exit. Now, you can also remove the file name echo code of the CMD_COPY function, Move in MSDOS echoes nothing.
Not really all that easy. Quit a bit of work there.