OS2 World.Com Forum
2012.05.25, 19:50:52 *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Looking for open DELTREE program?  (Read 3585 times)
sXwamp
Full Member
***
Posts: 223



View Profile WWW
« on: 2011.06.25, 06:08:46 »

I'm not a programmer, so bare that in mind please  Grin

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  Cry

Code:
/* 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?

Code:
/*
 * 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     = '';
ColorHighlight = '';
ColorNormal    = '';
ColorReset     = '';
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) */

« Last Edit: 2011.06.25, 06:35:12 by sXwamp » Logged
melf
Global Moderator
Hero Member
*****
Posts: 561



View Profile
« Reply #1 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.
Logged

/Mikael
sXwamp
Full Member
***
Posts: 223



View Profile WWW
« Reply #2 on: 2011.06.25, 18:45:20 »

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
« Last Edit: 2011.06.25, 18:48:13 by sXwamp » Logged
sXwamp
Full Member
***
Posts: 223



View Profile WWW
« Reply #3 on: 2011.06.25, 21:56:08 »

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.

Code:
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 Huh


Thanks,

Greggory
« Last Edit: 2011.06.25, 22:13:19 by sXwamp » Logged
ivan
Hero Member
*****
Posts: 562


View Profile
« Reply #4 on: 2011.06.25, 23:52:34 »

Attrib -r <dir> /S perchance?

ivan
Logged
nitro
Newbie
*
Posts: 7


View Profile
« Reply #5 on: 2011.06.26, 05:09:46 »

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.

Code:
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 Huh


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





Logged
sXwamp
Full Member
***
Posts: 223



View Profile WWW
« Reply #6 on: 2011.06.27, 01:35:11 »

Thanks for all the suggestions, but I finally got in touch with Dennis B and he is
allowing me to use his code.

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

 


« Last Edit: 2011.06.27, 01:48:34 by sXwamp » Logged
jep
Global Moderator
Sr. Member
*****
Posts: 402


View Profile
« Reply #7 on: 2011.06.27, 09:18:51 »

Hello,

a recursive version I use that you only call once and it'll handle the rest:
Code:
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.
Logged
Andi
Sr. Member
****
Posts: 252


View Profile
« Reply #8 on: 2011.06.27, 15:54:02 »

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?
Logged
abwillis
Sr. Member
****
Posts: 305


View Profile
« Reply #9 on: 2011.06.27, 16:55:56 »

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
Logged
sXwamp
Full Member
***
Posts: 223



View Profile WWW
« Reply #10 on: 2011.06.29, 07:42:34 »

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
Logged
Andi
Sr. Member
****
Posts: 252


View Profile
« Reply #11 on: 2011.06.29, 09:52:02 »

...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' Smiley Smiley Smiley
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.14 | SMF © 2006-2011, Simple Machines LLC Valid XHTML 1.0! Valid CSS!