![]()
[<<]Message[>>] [<<]Author[>>] Subject[>>] [<<]Thread
Number : 260 Date : 2001-06-21 Author : Kan Yabumoto Subject : Multi-step XXCOPY operations Size(KB) : 6
This message is a response to Gabe Fineman's excellent question on how to handle a complicated file-selection job which XXCOPY cannot handle. But, a multiple-step (batch file) solution is presented which can be applied to many other cases where XXCOPY cannot process certain combination of file-selection in one step. Here's Gabe's original question: >I have read Bulletin 17 on selecting files by date and still have a >question. I would like to delete files that meet three conditions > >1. They are marked as hidden >2. They were created more than 40 days ago (copied to this directory) >3. They have not been modified within the last 40 days > >I meet the first two conditions with the following command > >XXCOPY E:\Asivasrv\ /S/HO/Q1/YY /RS /ATH /FC/DB#40 > >I used the /FC switch to modify the /DB switch so that it refers to >the creation date and not the last modified date. I do not know what >would happen if I also use the /FW switch to modify another /DB#40 >switch. I understand from other bulletins that the order of switches >usually does not matter. > >Can I just say: > >XXCOPY E:\Asivasrv\ /S/HO/Q1/YY /RS /ATH /FC/DB#40 /FW/DB#40 > >-Gabe Fineman --------------------------------------------------------------------- Unfortunately, /FC and /FW are mutually exclusive switches controlling the single controllable behavior. As with other mutually exclusive groups of switches, when you specify two or more of switches in the same group, then, the switch which is evaluated last (specified at the rightmost position) will prevail, cancelling the earlier setting. SO, in your example, the /FW switch comes last which cancels the earlier /FC switch and the effect will be on both /DB#40 (the left hand side /DB#40 is cancelled by /DB#40 --- albeit identical in the case). Then, how can we handle the case in your question? Then answer is, there is no way to do this in one XXCOPY command. It needs a batch file script using other techniques which may look ugly. One that comes to my mind is to make a temporary reference directory where you add entries for the selected files using one filtering operation (in your example Step 1 and 2 which can be combined into one XXCOPY operation), and modify the list of files in the reference directory using Step 3 as an additional stage. In the third stage, you will use the list of files in the reference directory to work on the real destination. In the 4th and final stage, clean up the temporary directory. Let me give you this sequence in a batch file. (I have added Step 0 in the 1st line) CLEANUP.BAT ------------------------------------------------------------- xxcopy e:\xxtmp\ /rsy/h/r/yy/ed // clean up 1st xxcopy e:\asivasrv\ e:\xxtmp\ /s/h/fc/db#40/sz0 xxcopy e:\xxtmp\ /s/h/fw/da#39/rsy/pd0 xxcopy e:\asivasrv\ e:\xxtmp\ /s/h/rsy/pd0/u xxcopy e:\xxtmp\ /rsy/h/r/yy/ed // destroy this ------------------------------------------------------------- Step 1 (2nd line) uses /FC/DB#40 to select the file using the "creation date" and selects old files with age 40 or more days and copies these qualified files into the temporary directory. Since the temporary directory does not need the actual file contents (and we are not using the filesize in selection), /SZ0 was added to create zero-length files there. Step 2 (3rd line) removes files that are 39 days or younger in the temporary directory. ----------------------------------------------------------- Note that in Step 1, we used the "File-creation" time (/FC) which is the creation date of the file in that directory which is different from the way the file age is treated in Step 2. /FW in Step 2 uses the more traditional, "Last- written" file date. ------------------------------------------------------------ You may further eliminate more files using other criteria. /RSY/PD0 will delete the selected files in the directory without extra prompts. Once you are satisfied with what's left in the reference directory (I suggest while you are debugging this, you should stop at the end of third line), you can proceed with the 4th line which does the actual deletion in the target directory. Step 3 (4th line) uses /U in conjunction with the reference directory which selects all the files in the target directory (e:\asivasrv\) which are also present in the temporary directory. Again, /RSY/PD0 does the removal job for real. Step 4 (5th line) removes the temporary directory. ------------------------------------------------------ Gabe's original command line had both /H0 and /ATH. /ATH is synonymous to /H. Therefore /H0/ATH is the same as /H0/H which can be specified simply by /H. The /AT switch was added as a generalized scheme to handle any combination of attribute-based file selection. If the H-bit (hidden attribute) is the only concern here, /H is simpler and quite intuitive as well. ------------------------------------------------------ One nice thing about the recent (beta) versions of XXCOPY is that you may leave the "comment" field even in the batch file (the string starting at //). Although the batch file itself does not strip the comment field, the XXCOPY does recognize the double-slash sequence as the beginning of a comment filed, it works to your advantage. To be consistent within your batch file, you may use the alternate prefix for the comment (double-colon, ::). CLEANUP2.BAT ------------------------------------------------------------- @echo off :: my comment which is recognized by batch file xxcopy /ec e:\xxtmp\ /rsy/h/r/yy/ed :: clean up 1st xxcopy /ce e:\asivasrv\ e:\xxtmp\ /s/h/fc/db#40/sz0 xxcopy /ce e:\xxtmp\ /s/h/fw/da#39/rsy/pd0 :: here goes the real file-delete stage xxcopy /ce e:\asivasrv\ e:\xxtmp\ /s/h/rsy/pd0/u xxcopy /ce e:\xxtmp\ /rsy/h/r/yy/ed :: destroy this ------------------------------------------------------------- The /EC (only for the first XXCOPY line in a batch file) and /CE (in the remaining lines) switches makes the batch file handles the fatal errors gracefully. That is, when something abnormal happens earlier in the step, the subsequent XXCOPY steps will not be executed (to be precise, XXCOPY will be executed but will do nothing). More on this subject in XXTB #19 http://www.xxcopy.com/xxcopy/xxcopy19.htm ------------------------ I believe this message should be an article in XXCOPY technical bulletin. So, if you have problem following this article, please give me a feedback so that it can be polished before its publication in the Tech Bulletin section. TIA. Kan Yabumoto ================================================================
This message if part of XXCOPY's message Archive. The archive contains all the messages posted at Yahoo!Groups: XXCOPY.