/* * KD.CMD - V1.0 C.Langanke 2002 * * Syntax: kd dir [dir [...]] * * This program kills directory trees. * Names including blanks are not supported ! */ /* ***** BEGIN LICENSE BLOCK ***** * Version: CDDL 1.0 * * The contents of this file are subject to the COMMON DEVELOPMENT AND * DISTRIBUTION LICENSE (CDDL) Version 1.0 (the "License"); you may not use * this file except in compliance with the License. You may obtain a copy of * the License at http://www.sun.com/cddl/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is * "netlabs.org Open Source Archive Administrator/Client" * * The Original Distribution Package is named * "netlabs.org Open Source Archive Administrator/Client" * and maintained and distributed by the Initial Developer * and/or netlabs.org only. * * In addition to the CDDL the following applies: * If you modify the Original Code, you may distribute it only * as a part of a distribution package where * - the name of the package, created directories or * OS2.INI entries do not contain any of the terms * - "netlabs.org Open Source Archive" * - "NOSA" * - "NOSAC" * - "NOSAADM" * - neither netlabs.org nor the Initial Developer is stated as * the vendor or originator of the resulting Distribution Package, * which contains the Modified Code. * * The Initial Developer of the Original Code is * netlabs.org: Christian Langanke . * Portions created by the Initial Developer are Copyright (C) 1999-2008 * the Initial Developer. All Rights Reserved. * * Contributor(s): * * ***** END LICENSE BLOCK ***** */ SIGNAL ON HALT TitleLine = STRIP(SUBSTR(SourceLine(2), 3)); PARSE VAR TitleLine CmdName'.CMD 'Info Title = CmdName Info env = 'OS2ENVIRONMENT'; TRUE = (1 = 1); FALSE = (0 = 1); CrLf = '0d0a'x; Redirection = '> NUL 2>&1'; '@ECHO OFF' /* OS/2 Error codes */ ERROR.NO_ERROR = 0; ERROR.INVALID_FUNCTION = 1; ERROR.FILE_NOT_FOUND = 2; ERROR.PATH_NOT_FOUND = 3; ERROR.ACCESS_DENIED = 5; ERROR.NOT_ENOUGH_MEMORY = 8; ERROR.INVALID_FORMAT = 11; ERROR.INVALID_DATA = 13; ERROR.NO_MORE_FILES = 18; ERROR.WRITE_FAULT = 29; ERROR.READ_FAULT = 30; ERROR.GEN_FAILURE = 31; ERROR.INVALID_PARAMETER = 87; ERROR.ENVVAR_NOT_FOUND = 203; GlobalVars = 'Title CmdName CrLf env TRUE FALSE Redirection ERROR.'; /* eventually show help */ ARG Parm . IF ((Parm = '') | (POS('?', Parm) > 0)) THEN DO rc = ShowHelp(); EXIT(ERROR.INVALID_PARAMETER); END; call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs' call SysLoadFuncs /* dafault values */ GlobalVars = GlobalVars ''; rc = ERROR.NO_ERROR; DO UNTIL (TRUE) /* get parm */ PARSE ARG DirList; DO WHILE (DirList \= '') PARSE VAR DirList Dir DirList; rc = SysFileTree( Dir, 'Dir.', 'DO'); IF (rc \= 0) THEN DO SAY CmdName': error in SysFileTree, rc='rc; LEAVE; END; IF (Dir.0 \= 1) THEN DO SAY 'Warning: cannot find' Dir; LEAVE; END; Dir = Dir.1; /* get all subdirectories */ rc = SysFileTree( Dir'\*', 'Dir.', 'DOS'); /* kill anything moving ... ;-) */ DO d = Dir.0 TO 1 BY -1 rc = RemoveDirectory( Dir.d); END; rc = RemoveDirectory( Dir); END; rc = ERROR.NO_ERROR; END; EXIT( rc); /* ------------------------------------------------------------------------- */ HALT: SAY 'Abbruch durch Benutzer.'; EXIT(ERROR.GEN_FAILURE); /* ------------------------------------------------------------------------- */ ShowHelp: PROCEDURE EXPOSE (GlobalVars) /* show title */ SAY; SAY Title; SAY; PARSE SOURCE . . ThisFile /* skip header */ DO i = 1 TO 3 rc = LINEIN(ThisFile); END; /* show help text */ ThisLine = LINEIN(Thisfile); DO WHILE (ThisLine \= ' */') SAY SUBSTR(ThisLine, 7); ThisLine = LINEIN(Thisfile); END; /* close file */ rc = LINEOUT(Thisfile); RETURN(''); /* ------------------------------------------------------------------------- */ RemoveDirectory: PROCEDURE EXPOSE (GlobalVars) PARSE ARG Dir; /* remove attributes from files - does not work with option 'O' :-( */ rc = SysFileTree( Dir'\*', 'File.', 'F',, '-----'); /* remove files */ rc = SysFileTree( Dir'\*', 'File.', 'FO'); DO f = 1 TO File.0 rc = SysFileDelete( File.f); IF (rc \= ERROR.NO_ERROR) THEN SAY 'Warning: cannot delete file:' File.f; END; /* remove directory */ rc = SysRmDir( Dir); IF (rc \= ERROR.NO_ERROR) THEN SAY 'Warning: cannot delete direcory:' Dir; RETURN( rc);