Rev 37 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
43 | - | 1 | // ============================================================================ |
2 | // Create |
||
3 | // name : Andre Rikkert de Koe date: Mar 2018 |
||
4 | // descr : filefind |
||
5 | // This is a demo of programming in the Pascal language. |
||
6 | // Its part of a project to implement a program to create a directory |
||
7 | // tree similar to the output of the Unix find program. |
||
8 | // EUID : Any user who has read access to all the files being searched for. |
||
9 | // run : interactive |
||
10 | // |
||
11 | // Changes |
||
12 | // name : date: |
||
13 | // descr : short description |
||
14 | // |
||
15 | // ============================================================================ |
||
16 | |||
29 | - | 17 | program filefind; |
31 | - | 18 | Uses sysutils; |
29 | - | 19 | var directory : string; |
37 | - | 20 | var progname : string; |
29 | - | 21 | |
31 | - | 22 | // ============================================================================ |
23 | // Functions |
||
24 | // ============================================================================ |
||
25 | |||
37 | - | 26 | procedure Usage(mesg : string); |
27 | begin |
||
28 | Writeln('Usage: ' + progname + ' directory'); |
||
29 | Writeln(mesg); |
||
30 | end; |
||
31 | |||
29 | - | 32 | procedure traverse(directory : string); |
33 | var curdir1, curdir2 : string; |
||
30 | - | 34 | Info : TSearchRec; |
29 | - | 35 | pfile : string; |
36 | begin |
||
37 | curdir1 := GetCurrentDir; |
||
38 | chdir(directory); |
||
39 | curdir2 := GetCurrentDir; |
||
30 | - | 40 | FindFirst(directory + '/*', faAnyFile or faHidden, Info); |
29 | - | 41 | repeat |
30 | - | 42 | if ((Info.name <> '..') and (Info.name <> '.')) |
29 | - | 43 | then |
44 | begin |
||
30 | - | 45 | pfile := curdir2 + '/' + Info.name; |
29 | - | 46 | Writeln(pfile); |
47 | if (DirectoryExists(pfile)) |
||
48 | then |
||
49 | traverse(pfile) |
||
50 | end |
||
30 | - | 51 | until FindNext(Info) <> 0; |
29 | - | 52 | chdir(curdir1); |
53 | end; |
||
54 | |||
55 | procedure start_traverse(directory : string); |
||
56 | begin |
||
57 | Writeln(directory); |
||
58 | traverse(directory); |
||
59 | end; |
||
60 | |||
31 | - | 61 | // ============================================================================ |
62 | // Main |
||
63 | // ============================================================================ |
||
64 | |||
29 | - | 65 | begin |
37 | - | 66 | progname := ParamStr(0); |
29 | - | 67 | directory := ParamStr(1); |
30 | - | 68 | if (ParamCount = 1) |
29 | - | 69 | then |
30 | - | 70 | if DirectoryExists(directory) |
71 | then |
||
72 | start_traverse(directory) |
||
73 | else |
||
37 | - | 74 | Usage('ERROR: Not a directory : ' + directory) |
29 | - | 75 | else |
37 | - | 76 | Usage('ERROR: 1 argument expected'); |
29 | - | 77 | end. |