By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Changed order of folder names in @file

I am at a loss and hope someone can spread some light on this and tell me where it went wrong.

I have been running the below script for some time. AT one time it worked perfectly deleting all data over 89 days in the folder names listed in the cleanupset. There are two folders out of the whole directory tree that cannot be deleted at 90 days. We set up a for script with a listing of the folder names that we wanted to parse for files over 89 days.

Yesterday I noticed it was not deleting all the old data and thought one of the folders in the list may have caused it to die since there were no errors and I have an error capture in the script as well which always emailed me the results. So I reordered by list which is each directory name one per line. I took the last 10 folder names and out and added them at the top of the list.

There are no spaces in any of the lines holding the folder names.

Can you see what I did wrong please as a ton of data was deleted. Yes I had a synced server but it started replicating. Nightmare.

@echo off
set cleanupset=2009static-Xclude-JDR
set daysold=89
cd static3\imgdisk3
for %d in (@c:\robocopy\staticcleanup\%cleanupset.txt) for /[d-%daysold%,1/1/80] /h /a:d %s in (%d\*) del /s /x /y /z %s


This is the 4NT command log. It starts by deleting the files over 89 days and deletes them properly and after the letter R it just starts deleting the whole folder. I moved the folders from the letter S through Z to the top of the @file list. I am thinking it has been by some odd chance that this was not always creating a problem and the reordering obviously affected it immensely.

Seems simple to delete all files and folders over 89 days old except for two folders yet clearly I no longer have a script that does that.

Folders were deleted that were not in my @file list at all.

8/30/09 16:56:02][B044] del /s /x /y /z RZOO\09-01-06_16-25-46_RZOO >>f:\utils\logs\static3\CleanUp-2009-08-30-2009static-Xclude-JDR.log
[ 8/30/09 16:56:03][B044] for /[d-%daysold%,1/1/80] /h /a:d %s in (%d\*) del /s /x /y /z %s >>f:\utils\logs\static3\CleanUp-%_isodate-%cleanupset.log
[ 8/30/09 16:56:03][B044] for /[d-%daysold%,1/1/80] /h /a:d %s in (%d\*) del /s /x /y /z %s >>f:\utils\logs\static3\CleanUp-%_isodate-%cleanupset.log
[ 8/30/09 16:56:03][B044] del /s /x /y /z \RECYCLER >>f:\utils\logs\static3\CleanUp-2009-08-30-2009static-Xclude-JDR.log
[ 8/30/09 16:56:03][B044] There are no more files.
[ 8/30/09 16:56:03][B044] del /s /x /y /z \Static3 >>f:\utils\logs\static3\CleanUp-2009-08-30-2009static-Xclude-JDR.log
[ 8/30/09 16:56:03][B044] There are no more files.
[ 8/30/09 16:58:05][B044] There are no more files.
[ 8/30/09 17:00:35][B044] There are no more files.
PLEASE Changed order of folder names in @file

Sorry for the Bump but I am pulling my hair out as to why this occurred
dcohn wrote:
| @echo off
| set cleanupset=2009static-Xclude-JDR
| set daysold=89
| g:\
| cd\
| cd static3\imgdisk3
| for %d in (@c:\robocopy\staticcleanup\%cleanupset.txt) for
/[d-%daysold%,1/1/80] /h /a:d %s in (%d\*) del /s /x /y /z %s

You failed to mention the version of the command processor you use. It may
be significant.

Suspicious syntactic element.
You need to remember that a FOR variable whose name is a single letter, as
is %D in the outer FOR above, has special processing in the rest of the
command line: any occurrence of the two-character sequence %d is replaced
with the current value of D, even if you intended to use the value of
another variable whose name starts with D; the rest of that variable name is
retained literally. Suppose one of the lines in your indirect file is
"c:\abc"; when that line is processed the rest of the command line is parsed
after it has been translated to:

for /[d-c:\abcaysold%,1/1/80] /h /a:d %s in (%d\*) del /s /x /y /z %s

Now your date-range selection is not valid. A very simple generic solution
is to (almost) never use single letter variable names to control FOR loops.
In the current instant you could just change the variable name to any letter
other than D or S. Perhaps in an earlier version the name of either the FOR
control variable was not D, or the date control variable had a different
name. In any case, that's a simple change to make, and to try.

BTW, if you use V8 or later, there is a simpler form to specify files older
than x days: /![d-x]. One of many user suggestions implemented by Rex.

Using directory dates
Dates of directories are hardly ever relevant for any processing. Depending
on the version and build of the OS and of the file system used, a directory
date may be updated when you access a file or subdirectory. Your inner FOR
selects directories based on their "last modified" dates, and all files
regardless of age in directories not modified for 90 days.

General comments
Starting with 4nt8 a file exclusion range can include directory names. You
may find using just the two directory names not to be purged quicker than
building the list to be purged.

If the indirect file uses full pathnames to specify the directories which
are candidates for purging, changing CWD is not needed.

Suggested version

@echo off
set cleanupset=2009static-Xclude-JDR
set age=89
set atfile=c:\robocopy\staticcleanup\%cleanupset.txt
for %d in (@%atfile) del /![d-%age]/s /x /y /z %d\*

This assumes that the directory list in the cleanup set contains full
pathnames, and that those directories themselves are to be removed they
contain no recent files. The variable ATFILE is just used to make the FOR
command line shorter.
HTH, Steve
THANK YOU very much.

The 4NT version is quite old, version 5. We had updated the licenses to version 7 but did not change it on this relatively old W2K server.

The reason I went after directory for age was that the atlist contains the directories to run against. Each of those directories has one subdir per day added with that days images shot at the location. All the files are the same date within each subdir created selected. The subdirs are also using a format that may be a better option for me. For example. the folder name for today may be
09-08-31_01-30-35_IDLEWILD date_time_location. Each directory should have 90 subdirs within.

That said if I used a date mask to create the folder name each day I could delete the folder by name but it never seemed feasible.

Based on this and the fact that there is a related database entry which holds the path which is already deleted by the web app so that our 90 day restriction is in place I have requested that the developers supply me with a listing of the folder names that need to be purged each day.

I would then be able to eliminate the date check part and just delete based on the atfile.

I wish the developers did the file purging with the app but because of time crunch issues they do not have time to deal with it.

It is not a simple process since as I mentioned it really should be done by the webapp itself.

and Thanks for the assistance.


Similar threads