[<<]Message[>>]    [<<]Author[>>]    [<<]Subject[>>]    [<<]Thread[>>]

Number : 4773 Date : 2003-06-08 Author : Kan Yabumoto Subject : Re: Deleting unneeded files Size(KB) : 3
Bob G wrote: > To minimize backup file I use the following command line. > XXCOPY "C:\PROGRAM FILES\GRISOFT\AVG6\UPDATE\*.BIN" /ED/YY/ZS/RS/DB#30 > This eliminates all the files older than 30 days. > Can anyone suggest a way to eliminate all files except > the latest? If XXCOPY had a internal "sorting" function, this would be a breeze. The only "sorting" feature XXCOPY currently offers is in the /SG switch. Therefore, if there is a way, it must use the /SG switch in some creative way... Another observation is that you are trying to "rename" the file --- starts with *.BIN (with unique names) and ends up with just one file (I call it LATEST.BIN). Everyone knows XXCOPY doesn't do RENAMING... At first, I thought we could not do it. But, then, I came up with the following scheme. pick_latest.bat ----------------------------------------------- xxcopy \src\*.bin \temp\latest\ /rcy/yy xxcopy \temp\L*\ \temp\temp2\ /SL xxcopy \temp\temp2\ \temp\temp3\ /SXR xxcopy \temp\temp3\ \src\ /SGNo xxcopy \temp\ /RSY/S/YY ------------------------------------------------ This is the first time ever I used one type of the directory-flattening command and then use another type of reverse-directory-flattening feature. When you use /SL it will synthesize a file which contains the path into the filename separated by the backtick (`) character. After the first step, all the *.BIN files in the \src\ directory will be moved to the \temp\latest\ directory: \temp\latest\file1.bin \temp\latest\file2.bin \temp\latest\file3.bin ... Now, with xxcopy \temp\l*\ \temp\temp2\ /sl, you will get \temp\temp2\latest`file1.bin \temp\temp2\latest`file2.bin \temp\temp2\latest`file3.bin ... Then, xxcopy \temp\temp2\ \temp\temp3\ /SXR \temp\temp3\file1\latest.bin \temp\temp3\file2\latest.bin \temp\temp3\file3\latest.bin ... This is the trickiest part to understand this whole scheme. Normally, /SXR is to restore the original directory tree after a directory was flattened using /SX. But, in this case, we create /SL and reconstruct as if the files were copied by /SX. This technique (which I just discovered) will switch filename and the pathname in an intriguing way. Then, the file-gathering function xxcopy \temp\temp3\ \src\ /sgno will yield the \bin\latest.bin The /SGNO will gather all the files from the \temp\temp3\ directory and when the filename collides (all of them do), the newest (and only newest) one will be copied into the destination (the original directory) (This technique reminds me of the recombinant DNA in the genetic research.) If you don't fully understand this, you should run without the last line (the clean-up). The temporary directories will give you the intermediate results and will illustrate what is happening with this mess. The only possible (unlikely) problem that I can think of is what if you have a filename which has the rare character (`) in one of the files... One possibly useful variation is to remove the /RSY/YY switches which will not delete all the original files but create the LATEST.BIN file which is a copy of the latest file in the group. (Using the /SGoo in place of /SGNo, you may find the oldest file as well). This is a kludge at best. I would not call this as an "elegant" solution for this problem. But, it shows when a tool has a lot of things in it, some of the combinations of the many switches may provide an interesting behavior. I'm pretty sure that the resident Batch-file king, Garry can show a solution using dir, sort and a few simple tools to accomplish the same thing. I only wonder if his solution is shorter than 5 lines :-) Kan Yabumoto
This message if part of XXCOPY's message Archive. The archive contains all the messages posted at Yahoo!Groups: XXCOPY.