Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!mcvax!ukc!einode!tcdmath!jaymin From: jaymin@tcdmath.UUCP (Joe Jaquinta) Newsgroups: misc.wanted,comp.sources.d Subject: Re: Directory Tree display/printer Message-ID: <552@tcdmath.UUCP> Date: Thu, 27-Nov-86 14:04:01 EST Article-I.D.: tcdmath.552 Posted: Thu Nov 27 14:04:01 1986 Date-Received: Sat, 29-Nov-86 01:51:39 EST References: <415@ethz.UUCP> Reply-To: jaymin@tcdmath.UUCP (Joe Jaquinta) Organization: School of Mathematics, Trinity College, Dublin. Lines: 107 Xref: mnetor misc.wanted:271 comp.sources.d:50 In article <415@ethz.UUCP> srp@ethz.UUCP (Scott Presnell) writes: >Hello, >I have an interest in a program that will display the oragnization of a >directory tree in UNIX (or MSDOS)... Not exactly what you want but I find it *very* useful as a general program. j^2 To unbundle, run sh on this file... -----------------><--><--><------------------------- #!/bin/sh echo x - flst.1 sed 's/^X//' > flst.1 << '!End!Of!Sharchive!' X.TH flst 1 "Trinity College Dublin" X.SH NAME Xflst - fast listing sub-tree X.SH SYNOPSIS Xflst [directory(s)] X.SH DESCRIPTION X.I Flst Xlists a tree file system or systems specified in the argument Xwith indentation reflecting the level Xof nesting of the file in the file system. If no argument is Xgiven X.I flst Xtakes the current directory as default. X.SH SEE ALSO Xls(1), lstree(1) X.SH DIAGNOSTICS X.br XIt cannot list files nested more than twenty levels. !End!Of!Sharchive! echo x - flst.c sed 's/^X//' > flst.c << '!End!Of!Sharchive!' X#include X#include X#include X#include X Xint siz, level; Xchar tabs[] = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"; X Xmain(argc, argv) Xint argc; Xchar **argv; X{ X X level = 0; X siz = sizeof(struct direct); X if (argc == 1) X pdir(); X else while (*++argv) X if (chdir(*argv) >= 0) X pdir(); X else X iprint("Cannot access directory"); X} X Xpdir() X{ X struct direct entry; X struct stat filetyp; X int fp; X X fp = open(".", 0); X if (fp < 0) X { X iprint("Bad Open"); X return; X } X while (read(fp, &entry, siz)) X if (entry.d_ino) X { X stat(entry.d_name, &filetyp); X if (!strcmp(entry.d_name, ".q")) X continue; X if (!strcmp(entry.d_name, "..")) X continue; X if (!strcmp(entry.d_name, ".")) X continue; X iprint(entry.d_name); X if (filetyp.st_mode & S_IFDIR) X { X level++; X if (chdir(entry.d_name) >= 0) X pdir(); X else X iprint("Cannot access directory"); X level--; X } X } X close(fp); X chdir(".."); X} X Xiprint(string) Xchar *string; X{ X write(1, tabs, level); X write(1, string, strlen(string)); X write(1, "\n", 1); X} !End!Of!Sharchive! -- ...{decvax,seismo}!mcvax!ukc!einode!tcdmath!jaymin Io, the greek goddess of input and output. -- D. E. Knuth