I'm not a programmer, so bare that in mind please ;D
I wrote a program that deletes incremental backups directories past a certain number of days. but it partly uses someone else code (KILLTREE) that I can't rewrite yet. Does anyone have something that is simpler (deletes dir & files /w readonly attribs too) and that I can use freely? Here is my program that uses KILLTREE, I want to replace KILLTREE with something simplier:
I tried SysFileTree() and parsing the result, but kind of ended up deleting everything with that :'(
/* load the functions from the DLL REXXUTIL */
call rxFuncAdd 'SysLoadFuncs', 'REXXUTIL', 'SysLoadFuncs'
call SysLoadFuncs
CurrentDir = directory()
/* get todays date in base format */
Today=date('B')
Weekday=date('W')
/* number of days to backup */
NumDays = 14
/* calulates days to keep backed up */
LastWeek=Today-Numdays
say 'Today:' rxdates(today 'F') 'is 'rxdates(today 'W') ' -- ' NumDays 'days ago: 'rxdates(lastweek 'U') 'was a 'rxdates(lastweek 'W')
say ''
say ''
say 'This will keep incremental backups for the past ' || NumDays 'days.'
say ''
say 'And will delete any older backups past: '
say rxdates(lastweek 'F') || ' in the directory ' || CurrentDir || '\' || Weekday
say ''
say 'Do you want to continue y/n'
pull YesNo
if \ ((YesNo = "Y") | (YesNo = "y")) then exit
/* calulates the name of the weekday */
Weekday=rxdates(lastweek 'W')
/* delete cetain number of days back */
deleteDays = 90
/* dirToDelete contains the name of the directory */
/* to delete */
do deleteDays
LastWeek = LastWeek -1
/* calulates dirToDelete's name */
DateString = rxdates( LastWeek 'U')
Year = SubStr(DateString,7,2)
Month = SubStr(DateString,1,2)
Day = SubStr(DateString,4,2)
/* StandardDate = yyyymmdd */
StandardDate = '20' || Year || Month || Day
/* delete the directory tree */
say 'Deleting...'
dirToDelete = CurrentDir || '\' || Weekday || '\' || StandardDate
DelSuccess = killtree(dirToDelete)
end
And here is the KILLTREE that I'm using. Does anyone have something simpler that I can use?
/*
* REXXIT VERSION: 96.299a
* PROCESSED AT : Tue May 05 1998 08:45:54PM
* SOURCE : E:\DB\PROJECTS\OS2\KILLTREE\KILLTREE.X
* DESTINATION : .\OUT\KILLTREE.CMD
*/
/* @ START FILE: E:\DB\PROJECTS\OS2\KILLTREE\KILLTREE.X (Tue May 05 1998 08:45:50PM) */
ColorError = '[0;1;31m';
ColorHighlight = '[0;1;33m';
ColorNormal = '[0;32m';
ColorReset = '[0m';
AddRc = RxFuncAdd('SysFileTree', 'RexxUtil', 'SysFileTree');
call charout ,ColorHighlight;
say "[]--------------------------------------------------------------[]";
say "| KILLTREE.CMD, Version 98.125 (C)opyright by Dennis Bareis 1993 |";
say "| http://www.ozemail.com.au/~dbareis (db0@anz.com) |";
say "[]--------------------------------------------------------------[]";
say "";
call charout ,ColorReset;
Arguments = arg(1);
parse var Arguments TreeBase SubCommand;
parse upper var SubCommand SubCommand;
if TreeBase = "" then
call SyntaxError 'Expected the name of a directory to delete.';
Directory.0 = 0;
call SysFileTree TreeBase, 'Directory', 'DS'
if Directory.0 = 0 then
call SyntaxError 'The directory "' || TreeBase || '" does not exist.';
RoutineRc = 0;
call SysFileTree TreeBase || '\*.*', 'Directory', 'DS'
do i=1 to Directory.0
DoDir = (Directory.0 - i) + 1;
parse var Directory.DoDir DirDate DirTime DirSize DirAttr DirName;
DeleteRc = Delete1Dir(strip(DirName), SubCommand);
if DeleteRc <> 0 then
RoutineRc = DeleteRc;
end;
DeleteRc = Delete1Dir(TreeBase, SubCommand);
if DeleteRc <> 0 then
RoutineRc = DeleteRc;
exit(RoutineRc);
Delete1Dir:
ThisDir = arg(1);
SpecialCommand = arg(2);
say ColorNormal || 'Deleting: ' || ThisDir;
address cmd '@attrib -r -h -s ' || ThisDir || '\*.* >nul';
call charout ,ColorError;
if stream(ThisDir || '\*.*', 'c', 'query exists') <> '' then
do
address cmd '@del "' || ThisDir || '" /n >nul';
end;
address cmd '@rd "' || ThisDir || '" >nul';
call charout ,ColorReset;
return(Rc);
SyntaxError:
CallersLine = SIGL;
call charout ,ColorError;
say "This program deletes a directory tree. It will delete files which"
say "are protected (read-only etc).";
say "";
say "CORRECT SYNTAX";
say "~~~~~~~~~~~~~~";
say " KILLTREE[.CMD] DirName";
say "";
say "REASON";
say "~~~~~";
say " " || arg(1) || ColorReset || "";
exit(CallersLine);
Die:
exit(sigl);
/* @ END FILE: E:\DB\PROJECTS\OS2\KILLTREE\KILLTREE.X (processed 109 lines) */
Hi ,
The deltree from 2003 by Carl Harding was updated by him from deldir by Marc Polly (I don't know who they are, just reading from the readme). It's rexx and I guess it's ok to update again? Sys nothing about licensing or so. But I may miss your point.
Quote from: melf on 2011.06.25, 15:09:44
Sys nothing about licensing or so. But I may miss your point.
Nope exactly what I was talking about (licensing).
Where is the version that you are talking about ?Nevermind I found it here: http://www.os2site.com/sw/util/commandline/index.html
Thanks,
Greggory
Quote from: melf on 2011.06.25, 15:09:44
Hi ,
The deltree from 2003 by Carl Harding was updated by him from deldir by Marc Polly (I don't know who they are, just reading from the readme). It's rexx and I guess it's ok to update again? Sys nothing about licensing or so. But I may miss your point.
Ok, it was originally name DELDIR which I tried and it was later changed to DELTREE. Unfortunately,
it won't delete read-only files in either version.
SysFiletree(user_dir, dir_list, 'BO', '*****', '-----')This code is not working. Does anyone know how to remove the read-only attrib for the entire tree, before deleting it ???
Thanks,
Greggory
Attrib -r <dir> /S perchance?
ivan
Quote from: sXwamp on 2011.06.25, 21:56:08
Quote from: melf on 2011.06.25, 15:09:44
Hi ,
The deltree from 2003 by Carl Harding was updated by him from deldir by Marc Polly (I don't know who they are, just reading from the readme). It's rexx and I guess it's ok to update again? Sys nothing about licensing or so. But I may miss your point.
Ok, it was originally name DELDIR which I tried and it was later changed to DELTREE. Unfortunately,
it won't delete read-only files in either version.
SysFiletree(user_dir, dir_list, 'BO', '*****', '-----')
This code is not working. Does anyone know how to remove the read-only attrib for the entire tree, before deleting it ???
Thanks,
Greggory
I have a C program that does this but you are looking for a rexx routine.
To keep it simple, Once you have the filename list you could recursively use the atrib and del system calls for the files and rd for the directories.
This removes the attributes and deletes one file. Not Rexx but can can be modified.
@echo off
attrib -r -s -h %1
del %1
Thanks for all the suggestions, but I finally got in touch with Dennis B and he is
allowing me to use his code.
Directory.0 = 0;
call SysFileTree TreeBase, 'Directory', 'DS'
if Directory.0 = 0 then
call SyntaxError 'The directory "' || TreeBase || '" does not exist.';
RoutineRc = 0;
call SysFileTree TreeBase || '\*.*', 'Directory', 'DS'
do i=1 to Directory.0
DoDir = (Directory.0 - i) + 1;
parse var Directory.DoDir DirDate DirTime DirSize DirAttr DirName;
DeleteRc = Delete1Dir(strip(DirName), SubCommand);
if DeleteRc <> 0 then
RoutineRc = DeleteRc;
end;
DeleteRc = Delete1Dir(TreeBase, SubCommand);
if DeleteRc <> 0 then
RoutineRc = DeleteRc;
exit(RoutineRc);
Delete1Dir:
ThisDir = arg(1);
SpecialCommand = arg(2);
say 'Deleting: ' || ThisDir;
address cmd '@attrib -r -h -s ' || ThisDir || '\*.* >nul';
if stream(ThisDir || '\*.*', 'c', 'query exists') <> '' then
do
address cmd '@del "' || ThisDir || '" /n >nul';
end;
address cmd '@rd "' || ThisDir || '" >nul';
return(Rc);
So, if anyone is interested in setting up a 7 day or more incremental backup system with Rsync,
to a central server or local disk.
http://www.os2notes.com/os2backup.html
I'll be posting the directions in the next couple of days !!!
Greggory
Hello,
a recursive version I use that you only call once and it'll handle the rest:
RxRmDir: PROCEDURE
isOK = 1
CALL SysFileTree ARG(1)||'\*', 'folder.', 'DO'
DO i = 1 TO folder.0
isOK = ( ( RxRmDir( folder.i ) = 1 ) & isOK )
END
CALL SysFileTree ARG(1)||'\*', 'file.', 'FO'
DO j = 1 TO file.0
ADDRESS CMD '@attrib -r -h -s "'||file.i||'" >NUL'
isOK = ( ( SysFileDelete( file.j ) = 0 ) & isOK )
END
isOK = ( ( SysRmDir( ARG(1) ) = 0 ) & isOK )
RETURN isOK
Note: You can modify SysFileTree to do what "attrib" does.
Why not simply use
del * /s/x /[d01-01-08] (all files newer than 1.1.2008)
del * /s/x /[d-50,01-01-80] (all files not newer than 50 days)
from a 4os2 command prompt?
Well I uploaded to hobbes my version a little over a decade ago now:
http://hobbes.nmsu.edu/download/pub/os2/util/disk/diskutil.zip
I called it treegone, it will remove an entire tree regardless of read only attributes. As it is written it will prompt one time if you are sure you want to remove the tree and then it goes to town without prompting about specific files regardless of read only attribute. This package also has a small script to open a folder from the command line and another to change directories even across drives (I still use it occasionally but now that I use 4OS2 I don't really have need of it anymore).
Andy
Thanks everyone, I already have it working with Dennis B code. But may use Jep's code since it's pretty short.
Andi, it would be nice to use those two lines, but everyone doesn't have 4os2 installed. And I'll take a look at
the diskutil's abwills, thanks.
Greggory
Quote from: sXwamp on 2011.06.29, 07:42:34
...Andi, it would be nice to use those two lines, but everyone doesn't have 4os2 installed....
One line for the initial purpose. It's delivered with eCS and I think installed by default. Moreover it's open source everyone can download it freely. A must have for everyone using the command line. Argue 'doesn't have 4os2' is for me on a similar level as 'doesn't have REXX' :) :) :)