Rev 37 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 37 | Rev 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 | ||
1 | program filefind; |
17 | program filefind; |
2 | Uses sysutils; |
18 | Uses sysutils; |
3 | var directory : string; |
19 | var directory : string; |
4 | var progname : string; |
20 | var progname : string; |
5 | 21 | ||
6 | // ============================================================================ |
22 | // ============================================================================ |
7 | // Functions |
23 | // Functions |
8 | // ============================================================================ |
24 | // ============================================================================ |
9 | 25 | ||
10 | procedure Usage(mesg : string); |
26 | procedure Usage(mesg : string); |
11 | begin |
27 | begin |
12 | Writeln('Usage: ' + progname + ' directory'); |
28 | Writeln('Usage: ' + progname + ' directory'); |
13 | Writeln(mesg); |
29 | Writeln(mesg); |
14 | end; |
30 | end; |
15 | 31 | ||
16 | procedure traverse(directory : string); |
32 | procedure traverse(directory : string); |
17 | var curdir1, curdir2 : string; |
33 | var curdir1, curdir2 : string; |
18 | Info : TSearchRec; |
34 | Info : TSearchRec; |
19 | pfile : string; |
35 | pfile : string; |
20 | begin |
36 | begin |
21 | curdir1 := GetCurrentDir; |
37 | curdir1 := GetCurrentDir; |
22 | chdir(directory); |
38 | chdir(directory); |
23 | curdir2 := GetCurrentDir; |
39 | curdir2 := GetCurrentDir; |
24 | FindFirst(directory + '/*', faAnyFile or faHidden, Info); |
40 | FindFirst(directory + '/*', faAnyFile or faHidden, Info); |
25 | repeat |
41 | repeat |
26 | if ((Info.name <> '..') and (Info.name <> '.')) |
42 | if ((Info.name <> '..') and (Info.name <> '.')) |
27 | then |
43 | then |
28 | begin |
44 | begin |
29 | pfile := curdir2 + '/' + Info.name; |
45 | pfile := curdir2 + '/' + Info.name; |
30 | Writeln(pfile); |
46 | Writeln(pfile); |
31 | if (DirectoryExists(pfile)) |
47 | if (DirectoryExists(pfile)) |
32 | then |
48 | then |
33 | traverse(pfile) |
49 | traverse(pfile) |
34 | end |
50 | end |
35 | until FindNext(Info) <> 0; |
51 | until FindNext(Info) <> 0; |
36 | chdir(curdir1); |
52 | chdir(curdir1); |
37 | end; |
53 | end; |
38 | 54 | ||
39 | procedure start_traverse(directory : string); |
55 | procedure start_traverse(directory : string); |
40 | begin |
56 | begin |
41 | Writeln(directory); |
57 | Writeln(directory); |
42 | traverse(directory); |
58 | traverse(directory); |
43 | end; |
59 | end; |
44 | 60 | ||
45 | // ============================================================================ |
61 | // ============================================================================ |
46 | // Main |
62 | // Main |
47 | // ============================================================================ |
63 | // ============================================================================ |
48 | 64 | ||
49 | begin |
65 | begin |
50 | progname := ParamStr(0); |
66 | progname := ParamStr(0); |
51 | directory := ParamStr(1); |
67 | directory := ParamStr(1); |
52 | if (ParamCount = 1) |
68 | if (ParamCount = 1) |
53 | then |
69 | then |
54 | if DirectoryExists(directory) |
70 | if DirectoryExists(directory) |
55 | then |
71 | then |
56 | start_traverse(directory) |
72 | start_traverse(directory) |
57 | else |
73 | else |
58 | Usage('ERROR: Not a directory : ' + directory) |
74 | Usage('ERROR: Not a directory : ' + directory) |
59 | else |
75 | else |
60 | Usage('ERROR: 1 argument expected'); |
76 | Usage('ERROR: 1 argument expected'); |
61 | end. |
77 | end. |
62 | 78 |