{Begin SubSec Manipulating Tenex File Directories from Interlisp-10}
{Title Manipulating Tenex File Directories from Interlisp-10}
{Text

The following function allows the user to conveniently specify and/or program a variety of directory operations:


{FnDef {FnName DIRECTORY} {FnArgs FILES COMMANDS DEFAULTEXT DEFAULTVERS {anonarg}}
{Text

{note {fn DIRECTORY} was written by L.M. Masinter.}

{arg FILES} is either [1] {lisp NIL} (which is equivalent to {lisp *.*;*}); or [2] an atom which can contain {lisp $}'s or {lisp *}'s (equivalent) which match any number of characters or {lisp ?}'s which match a single character, or else [3] {arg FILES} is a list of the form
{lisp ({arg FILES} + {arg FILES})},
{lisp ({arg FILES} - {arg FILES})},
or {lisp ({arg FILES} * {arg FILES})},{foot
{lisp OR} can be used for {lisp +}, and {lisp AND} for {lisp*}.
}{comment endfootnote}
e.g., {lisp (T$ + $L)} will match with any file beginning with {lisp T} or ending in {lisp L}, {lisp (T$ - *.DCOM)} matches all files that begin with {lisp T} and are not {lisp .DCOM} files.

For each file that matches, each command in {arg COMMANDS} is executed with the following interpretation:


{Begin LabeledList interpretation of DIRECTORY commands}

{Label {lisp @ {arg FN}}}
{Item
Apply {arg FN} to the JFN for each file; if {arg FN} returns {lisp NIL}, abort command processing for this file.  If {arg FN} is a function of two arguments, it will be passed the name of the file as its second argument.

{note in Interlisp-D??}
}


{Label {lisp P}}
{Item
Print file name.
}


{Label {lisp PAUSE}}
{Item
Wait for user to type any char (good for display if you want to ponder).
}


{Label {lisp PROMPT {arg MESS}}}
{Item
Prompts with {arg MESS}; if user responds with {lisp N}o, abort command processing for this file.
}


{Label {lisp SIZE}}
{Item
Print file size.
}


{Label {lisp TRIMTO {arg N}}}
{Item
Deletes all but {arg N} versions of file ({arg N}{GE}0).
}


{Label {lisp OUT {arg FILE}}}
{Item
Directs output to {arg FILE}.
}


{Label {lisp COLLECT}}
{Item
Adds file on value list.  In this case the value of {fn DIRECTORY} will be the list of files (complete file names) collected.
}


{Label {lisp DATE}}
{Item
Prints date the file was last written.
}


{Label {lisp DELETE}}
{Item
Deletes file.  If this is specified, the value of {fn DIRECTORY} is {lisp NIL} if no {lisp COLLECT} command is specified, otherwise the list of files deleted.
}


{Label {lisp DELETED}}
{Item
Prints out those files that have been deleted.
}


{Label {lisp UNDELETE}}
{Item
Undeletes the indicated files that have been deleted.
}

{End LabeledList interpretation of DIRECTORY commands}


{fn DIRECTORY} uses {fn DIRCOMMANDS} to correct spelling, which also provides a way of defining abbreviations and synonyms (see {SectionRef L!SpellingLists} on spelling lists).  Currently the following abbreviations are recognized:


{Begin LabeledList abbreviations}

{Label {lisp TI}}
{Item
same as {lisp DATE}
}


{Label {lisp DEL}}
{Item
same as {lisp DELETED}
}


{Label {lisp DEL?}}
{Item
same as {lisp PROMPT "delete?" DELETE}
}


{Label {lisp COLLECT?}}
{Item
same as {lisp PROMPT "?" COLLECT}
}

{End LabeledList abbreviations}
}}


{index *PRIMARY* DIR PA}

There is also a lispxmacro {pacom DIR} which calls the function {fn DIRECTORY}:

{ComDef {Type PA} {Name DIR {arg FILES} {arg COMMANDS}}
{Text
calls the function {fn DIRECTORY} with {lisp (P . {arg COMMANDS})} as the command list and {lisp *} and {lisp *} as the default extension and default version respectively.
}}

For example, to {lisp DELVER} only those files which you ok, do
{lisp DIR {arg FILES} PROMPT "?" TRIMTO 1}.


{Begin Note}
Date: 19 NOV 1978 1550-PST
From: MASINTER

Fixed DIRECTORY to put back in the TRIMTO option (request from Vittal, as the OLDVERSIONS feature I had put in before did not work for TOPS-20. Note that several versions ago, I installed a new DIRECTORY package with several new features which I need to document -in particular, I moved over some of the things which were in EXEC where the cost of having them in the code was slight). Main important feature is that the DELETE and UNDELETE options of a DIR command are undoable; /DELFILE and /UNDELFILE are included in the system. 
{End Note}

{Begin Note}
Date: 3 Dec 1978 3:57 pm (Sunday)
From: Masinter
Subject: new DIR features

a couple of weeks (months?) ago, I installed a new version of the DIRECTORY package, with a couple of things cleaned up. This version has been stable long enough that I am now documenting the new features.

The following is a complete list of the 'commands' recognized by the DIRECTORY processor (some of these are old, and some are new):

commands which print something:

P	prints file name
PP	prints file name sans version (used by NDIR)

SIZE, READDATE, WRITEDATE, CREATIONDATE, LENGTH, BYTESIZE, 
PROTECTION, AUTHOR
	prints the appropriate information returned by GETFILEINFO.
	(the list fileinfotypes provides additional formatting information to
	the directory function).

"string"		print the given string


commands which affect the value returned:

COLLECT   	the value of DIRECTORY is a list of file names; add
		this file name to that list
COUNTSIZE	the value of DIRECTORY is a sum. Add the SIZE of
		this file to the sum.


interactive commands:

PAUSE	wait until the user types something before proceeding with
	the rest of the commands.

arbitrary expression or predicate:

@ expression	the expression following an @-sign is either a function
		of one argument (JFN), a function of two arguments
		(JFN FILENAME) or an arbitrary expression which uses
		JFN and/or FILENAME freely. (it is a minor efficiency hack
		that if FILENAME is not used in the expression, it isn't
		computed).

OLDERTHAN n	proceed if the file hasn't been referenced (read or 
		written) in n days; e.g. DIR *.* OLDERTHAN 90 P DELETE
		will delete all files not referenced in 90 days).

BY user	proceed if the file was last written by the given user.

OLDVERSIONS n	proceed if there are at least n more recent versions
		of the same file (note that this IS NOT IMPLEMENTED for
		TOPS20 and DIRECTORY will complain if you try to
		use it on a TOPS-20 system). For example, to delete all
		but the most recent version of a file,
		DIR FILE OLDVERSIONS 1 P DELETE

set internal directory state:

DELETED	allow DIRECTORY to examine deleted files (normally, they
		are not mapped over).
OUT filename	direct all output to given filename
COLUMNS n	attempt to format output in n columns (rather than
		just 1).

perform actions on the given file:

DELETE	delete the file (undoably!)
UNDELETE	un-delete the file (undoably!). This also does a 'DELETED'
		so that DIRECTORY only considers deleted files.


As before, DIRCOMMANDS is used as a spelling list and to supply defaults and
abbreviations. Valid shorthand commands are:

AU 		 AUTHOR
-  		 PAUSE
COLLECT?	PROMPT " ? " COLLECT
DA, TI		WRITEDATE
DEL		DELETE
DEL?, DELETE?	PROMPT " delete? " DELETE
OLD		OLDERTHAN 90
PR		PROTECTION
SI		SIZE



Also as part of the DIRECTORY package, the functions

/delfile[filename]	delete filename (undoably).
undelfile[filename]	undelete filename
/undelfile[filename]	undelete filename (undoably)

are provided. At type-in, delfile is converted to /delfile.
{End Note}


}{End SubSec Manipulating Tenex File Directories from Interlisp-10}