MODULE InfoForEachFile;

	(*
	Do for all documents
	Helmut Zinn - 

	"InfoForEachFile.Test"
	*)

	IMPORT
		Dialog, DosKeyboard, (* DosSort, *) Files, StdLog, Strings;

	TYPE
		Function = PROCEDURE (IN path, filename, filetype: ARRAY OF CHAR);

	VAR
		Task: Function;
		includeSubdirectories: BOOLEAN;
		count: INTEGER;

	PROCEDURE Log (IN path, filename, filetype: ARRAY OF CHAR);
	BEGIN
		StdLog.Int(count); StdLog.Char(' '); StdLog.String(filename); StdLog.Ln;
	END Log;

	PROCEDURE Search (IN path: ARRAY OF CHAR);
		VAR
			files: Files.FileInfo; dirs: Files.LocInfo;
			loc: Files.Locator; p: Files.Name;
	BEGIN
		loc := Files.dir.This(path);
		files := Files.dir.FileList(loc);
		(* DosSort.FileList(files); *)
		WHILE ~DosKeyboard.Break() & (files # NIL) DO
			INC(count);
			Strings.IntToString(count, p);
			p := p + ' ' + path + files.name;
			Dialog.ShowStatus(p);
			Task(path, files.name, files.type);  (* do the task for each file *)
			files := files.next
		END;
		IF includeSubdirectories THEN
			loc := Files.dir.This(path);
			dirs := Files.dir.LocList(loc);
			(* DosSort.LocList(dirs); *)
			WHILE ~DosKeyboard.Break() & (dirs # NIL) DO
				p := path + dirs.name + "/";
				Search(p);
				dirs := dirs.next
			END;
		END;
	END Search;

	PROCEDURE Do* (task: Function; IN path: ARRAY OF CHAR; include: BOOLEAN);
	BEGIN
		Task := task;
		includeSubdirectories := include;
		count := 0;
		Search(path);
		Dialog.ShowStatus("");
		IF DosKeyboard.Break() THEN DosKeyboard.ResetBreak END;
	END Do;

	PROCEDURE Test*;
	BEGIN
		Do(Log, "Help/", TRUE);
	END Test;

END InfoForEachFile.
