Re: How to ... ?



On Wed, 25 Jan 2006 21:38:38 UTC, "Dan-the K" <kaliushkin@xxxxxxx>
wrote:

> Did it! After some time on the learning curve, I was able to do
> everything with one command. The date range was good, /X parameter
> removes empty directories, and /N lets you give it a try and see what
> it would do if it were run for real.

> I'm very comfortable with command lines so this was great.
>
> Dan
>

It sounds as if the OP has found a solution that works for him, but I
may as well throw this quick-and-dirty into the pot. It may help
someone else.
This a REXX program that cleans out files over 1 year old.
Its strength is very low user involvement. Its weakness is very low
flexibiltiy.
You may change the 'root' folder, it does not have to be the root of
the drive,
by changing this line in the program

CALL next 'F:'
/* Set the 'root' of the area to be cleared. */

If you specify another directory do not use a trailing backslash.

You can change the cutoff date by changing the number in this line in
the program
It is set for 1 year.

gonedate = Date( 'S') - 10000
/* Set the cutoff date here. */

When the program starts it will walk the directory tree from your
chosen root out to the 'leaf' directory(s) and delete old files. When
it has finished deleting from a directory it will check to see if the
directory is empty.
If so, it will remove the directory.

If you cut this out watch out for line wraps.

-------------------------------- Snip
--------------------------------------------------

/* OLDSGONE REXX CMD by Gord Snider v01.00 2006-01-26 */
/* PURPOSE: To remove from Drive F: all files that have not been
updated in the last year.

SYNTAX: OLDSGONE [/?]

/? optional switch to show this help screen and exit.

This cmd will start by issuing the DATE command and capturing the
reply. IT IS YOUR RESPONSIBILITY TO SEE THAT THE SYSTEM DATE IS
CORRECTLY SET BEFORE RUNNING THIS.
Then this cmd will search drive F: folder by folder and in each
folder it will delete all files whose dates are older than one year.
Then it checks the folder to see if the folder is empty. If it is
it will delete the folder. 'Empty' means there are no files or
subfolders left in it.
If you miss running this cmd for one or more days and there were
files eligible for deletion on any of those days they will be
deleted at the next execution.
If you run this more than once in one day there should be no files
removed after the first execution.
*/

Call RxFuncAdd 'SysLoadFuncs', 'REXXUTIL', 'SysLoadFuncs'
Call SysLoadFuncs

parse arg myargs '/'switches +0

opt. = 0 /* unset options will
be FALSE */
mod. = '' /* unset modifications
will be NULL */
do while pos( '/', switches) ª= 0 /* each option must
have leading slash */
parse var switches '/'opt'/'switches +0 /* parse out the next
option/modification set */
parse upper var opt opt 2 mod /* split the option
from any mod */
opt.opt = 1 /* capture the option
value and set it to TRUE */
mod.opt = mod /* capture the
option's modification */
end

if opt.? then do /* Help screen */
do l = 1 to sourceline() while left( sourceline( l), 2) ª= '*' ||
'/'
say sourceline( l)
if l // 22 = 0 then do
say ' Hit <Enter> to continue ...'
pull .
end
end l
exit
end /* if opt.? */

gonedate = Date( 'S') - 10000
/* Set the cutoff date here. */

/* This is set for one year old. */
CALL next 'F:' /* it is set for drive F: */ /*
Set the 'root' of the area to be cleared. */
EXIT 0
/* Does not have to be a drive root. */

next: PROCEDURE EXPOSE gonedate
PARSE ARG nextdir

CALL SysFileTree nextdir || '\*', 'dir.', 'DO'
/* Record all subdirs in this dir. */

DO dir = 1 TO dir.0
/* Step thru each one. */
CALL next dir.dir
/* Reaching for a 'leaf' folder. */
END dir

/* 'Leaf' folder found. */
CALL SysFileTree nextdir || '\*', 'file.', 'FL'
/* Find files eligible for deletion. */
DO i = 1 TO file.0
PARSE VAR file.i yr '-' mo '-' dy . . . name .
filedate = yr || mo || dy
IF filedate < gonedate THEN DO
/* Yes, it's eligible. */
CALL SysFileTree name, 'name.', 'FO',,'-*---'
/* Clear file attribute bits. */
code = SysFileDelete( name)
/* Delete the file. */
IF code = 0 THEN
SAY 'Deleted' file.i
ELSE DO
SAY 'Not Deleted. rc=' code file.i
END
END
END i

CALL SysFileTree nextdir || '\*', 'both.', 'B'
/* Anything left in folder? */
IF both.0 = 0 THEN DO
/* If empty, delete the folder. */
CALL SysFileTree nextdir, 'both.', 'F',, '-+---'
/* Clear folder attribute bits. */
code = SysRmDir( nextdir)
/* Remove empty folder. */
IF code = 0 THEN
SAY 'Removed' nextdir
ELSE DO
SAY 'Not Removed. rc=' code nextdir
END
END

RETURN

----------------------------------------------Snip
---------------------------------------------------------
--
Gordon Snider
Toronto, Canada
.



Relevant Pages

  • Re: Sysvol not replicating but no NTFRS errors
    ... NTFRSUTIL command returns the current root directory for the SYSVOL ... staging folder. ... Note The path that is reported by the LINKD command varies depending on ...
    (microsoft.public.windows.server.active_directory)
  • Re: Distributed File System / File Replication Service
    ... When running the first command, the primary server reports: The system cannot find the file specified which I think is probably ok since I have already unshared that folder and everything. ... In the Distributed File System snap-in, right-click the root target you want to remove, and then click Remove Target. ...
    (microsoft.public.windows.server.active_directory)
  • Re: Terminal
    ... Trying to move from sg1 to desktop what is the exact command. ... Seems like you are still root. ... every folder and file you enter exists. ... that's the root's home folder, ...
    (Ubuntu)
  • Re: XP files question
    ... just use a subdirectory in the root directory - is there any reason ... On XP there isn't any reason not to create a folder for this ... The use the old dir command with the /x keyword. ... (the ">" represents the command prompt. ...
    (microsoft.public.windowsxp.basics)
  • RE: Locating corrupt driver
    ... This article describes the functionality and limitations of the Windows ... Create and format partitions on drives. ... MB of hard disk space on your system partition to hold the Cmdcons folder ... Windows NTBoot Console Command Interpreter. ...
    (microsoft.public.win2000.applications)