* ///////////////////////////////////////////
* DLIB.KEX Written by Kenneth Reiss 6/8/93
* 114-R Pennington Avenue
* Passaic, New Jersey 07055
* Kedit 5.0
*
*
* usage: kedit flist (prof dlib.kex
*
* I needed a way to delete a tremendous amount of files from
* one of the LAN Servers I administer at work.
*
* While there are many utilities which allow you to mark and
* delete files, this is often a laborous task especially as
* in my case where I had to delete several thousand files in
* hundreds of directories (really!).
*
* Files on the LAN which are more than six months old are
* considered inactive so, I needed a way to sort out those
* files and create a batch job to delete them.
*
* I created a file list of the entire drive by issuing the
* DOS (OS/2) command 'DIR /S > flist'. Then I created the following
* KEXX script to remove active files from the list. DLIB.KEX takes the
* month and year as its parameters in the form MM YY .
* It then removes all files from the list whose date stamp is greater than
* that date.
*
* If the month is a single digit (June = 6) just put in the single
* digit. The script will pad with a space (" 6") so it matches
* the DIR listing.
*
* cleanlist: procedure
*
* For instance, if you wanted to create a batch file to act
* on files 6 or more months old, you would give DLIB.KEX the
* parameters (it is June, 1993) 12 93. The script then goes
* through the file flist and removes all lines listing files
* whose date stamp is after the year 92 and after the month
* 12 (December).
*
* Of course in this type of comparison if the year is 93 then
* fine, it is greater that 92 but if the date is January, 93
* then the comparison of months will fail. 1 (January) is less
* than 12 (December). In order to get around this, the script
* compares the years. If the year of the file is greater than
* the year you feed the script then 12 is added to the month to
* force the subsequent comparison to work. So, instead of 1 93
* the script uses 13 93. 13 is greater that 12 and 93 is greater
* than 92!
*
* DLIB.KEX also deletes extraneous lines from flist such as lines
* listing directories,
, total number of files and bytes:
*
* 23 file(s) 919874 bytes used
*
* Total files listed:
* 6766 file(s) 281812861 bytes used
* 2859008 bytes free
*
*
* fullspec: procedure
*
* fullspec examines the remaining lines, gets rid of the file size,
* date and time information then creates a fully specified filename.
*
* /Directory/ is used to find the full path specification for the file
* (newspec: procedure, which is called by fullspec).
*
* This is saved in a variable then, that directory line is removed.
* Next fullspec creates a legal file name by removing any padded spaces
* from the file name field, concatenates a dot (.) and concatenates the
* file extension.
*
* do while ptr > 0
* if substr(fna, ptr, 1) = " " then ptr = ptr - 1; else leave
* end
*
* fna = substr(fna, 1, ptr) || "." || fe
*
* The variable blank is a string of 40 spaces which is concatenated to the
* legal file name so when the file name is coverlay(ed) it wipes out the
* file size, date and time information from the line.
*
* Lastly, the path specification is cinsert(ed) into the line creating
* a fully specified, legal file name.
*
* batchready: procedure
* This procedure inserts replaceable parameters before and after each
* file name producing the final output of:
*
* %1 %2 %3 C:\FILE.EXT
*
* I have to archive the files before I delete them so having 3 parameters
* before the file name allows you to use ARC or PKZIP quite easily.
*
* Later when I have to delete the files I call the batch file with the DOS
* command DEL. %2 and %3 become NUL arguments so, DOS (OS/2) ignores them.
*
* I rem'ed out the following lines:
*
* 'cinsert %1 '
* 'clocate :'length.1() + 1
* 'cinsert %2'
*
* These lines would produce output like this:
*
* %1 C:\FILE.TXT %2
*
* So you could use this as a batch file that copies selected files:
*
* COPY C:\FILE.TXT D:\ARCHIVE
*
*
* To finish up, DLIB.KEX changes flist 's file extension to 'bat'
* then ffile's it. I like to keep the original flist - just in case...
*
* Note that this will work with DOS and OS/2 FAT type listings. OS/2's
* HPFS DIR output displays the file name as the last field of each line
* and displays legal filenames.
*
* I used DLIB.KEX to parse a list of 8000 entries to produce a batch file
* containing some 3700 entries. It took about 3 minutes on my PS/2 90.
*
* - qed -
* ///////////////////////////////////////////
call cleanlist
call fullspec
call batchready
'emsg change fileid to bat'
'fext bat'
'emsg saving batch file'
'ffile'
'emsg Success! B''bye'
exit
* ///////////////////////////////////////////
cleanlist: procedure /* take listing from DOS DIR /s command, remove all entries, file(s) entries and files with a date of 1993 */
/* to subsequently make a batch file to act on remaining file list */
call beep 500, 250 /* get users attention for input prompt */
call beep 750, 125
'emsg Input Month and Year as MM YY'
parse linein mm yy
'emsg cleanlist: procedure'
':1'
do 4; 'del'; end
do while focuseof() = 0
fline = curline.3()
mm_comp = substr(fline, 25, 2) /* if the year of the file is greater than */
yy_comp = substr(fline, 31, 2) /* the focus year then, add 12 to the month */
if yy_comp > yy then mm_comp = mm_comp + 12 /* to force the month comparison to work */
if mm_comp < 10 then mm = " " || mm /* pad single digit month e.g. " 6" */
if (mm_comp > mm & yy_comp > yy ) | substr(fline, 11, 7) == "file(s)" | substr(fline, 14, 5) == "" | fline = "" then 'del'
else 'down'
end
'bot'
'del' /* delete 'total number of bytes' line in DOS dir listing */
'-1'
'del' /* delete 'total number of files' line in DOS dir listing */
'top'
return
* ///////////////////////////////////////////
fullspec: procedure
'emsg fullspec: procedure'
blanks = "________________________________________" /* overlay command uses underscore to represent (40) spaces */
'top'
spec = newspec(argh)
do while spec <> "no more"
if substr(curline.3(), 2, 9) <> "Directory" then
do
fna = substr(curline.3(), 1, 8)
fe = substr(curline.3(), 10, 3)
ptr = 8
do while ptr > 0
if substr(fna, ptr, 1) = " " then ptr = ptr - 1; else leave
end
fna = substr(fna, 1, ptr) || "." || fe
'overlay' fna || blanks /* the rest of the record */
'cinsert' spec /* insert full directory specification before filename */
'down'
if focuseof() then leave
end
else
spec = newspec(argh)
end
return
newspec: procedure
'-1'
'/Directory/'
if rc = 0 then
do
spec=substr(curline.3(), 15,)
if substr(curline.3(), length.1(), 1) <> "\" then spec = spec || "\"
'del' /* delete Directory header line after we get spec */
end
else
spec = "no more"
/* if no more Directory lines return spec to force calling */
/* routine to break out of loop */
return spec
* /////////////////////////////////////////////
batchready: procedure
'emsg batchready: procedure'
':1'
do while focuseof() = 0 /* insert replaceable parameters for ARC.EXE */
do /* %1 %2 %3 C:\FILE.EXT %4 */
'clocate :1' /* e.g. ARC A C:\FILE.EXT ARCHIVE */
'cinsert %1 %2 %3 '
** 'cinsert %1 ' /* remark out the line above and include */
** 'clocate :'length.1() + 1 /* these 3 lines to make a copy batch file */
** 'cinsert %4' /* %1 C:\FILE.TXT %2 */
/* e.g. COPY C:\FILE.TXT D:\ARCHIVE */
'd'
end
end
return
* //////// end of file dlib.kex ////////////