Rev 31 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
29 | - | 1 | program filefind; |
31 | - | 2 | Uses sysutils; |
29 | - | 3 | var directory : string; |
37 | - | 4 | var progname : string; |
29 | - | 5 | |
31 | - | 6 | // ============================================================================ |
7 | // Functions |
||
8 | // ============================================================================ |
||
9 | |||
37 | - | 10 | procedure Usage(mesg : string); |
11 | begin |
||
12 | Writeln('Usage: ' + progname + ' directory'); |
||
13 | Writeln(mesg); |
||
14 | end; |
||
15 | |||
29 | - | 16 | procedure traverse(directory : string); |
17 | var curdir1, curdir2 : string; |
||
30 | - | 18 | Info : TSearchRec; |
29 | - | 19 | pfile : string; |
20 | begin |
||
21 | curdir1 := GetCurrentDir; |
||
22 | chdir(directory); |
||
23 | curdir2 := GetCurrentDir; |
||
30 | - | 24 | FindFirst(directory + '/*', faAnyFile or faHidden, Info); |
29 | - | 25 | repeat |
30 | - | 26 | if ((Info.name <> '..') and (Info.name <> '.')) |
29 | - | 27 | then |
28 | begin |
||
30 | - | 29 | pfile := curdir2 + '/' + Info.name; |
29 | - | 30 | Writeln(pfile); |
31 | if (DirectoryExists(pfile)) |
||
32 | then |
||
33 | traverse(pfile) |
||
34 | end |
||
30 | - | 35 | until FindNext(Info) <> 0; |
29 | - | 36 | chdir(curdir1); |
37 | end; |
||
38 | |||
39 | procedure start_traverse(directory : string); |
||
40 | begin |
||
41 | Writeln(directory); |
||
42 | traverse(directory); |
||
43 | end; |
||
44 | |||
31 | - | 45 | // ============================================================================ |
46 | // Main |
||
47 | // ============================================================================ |
||
48 | |||
29 | - | 49 | begin |
37 | - | 50 | progname := ParamStr(0); |
29 | - | 51 | directory := ParamStr(1); |
30 | - | 52 | if (ParamCount = 1) |
29 | - | 53 | then |
30 | - | 54 | if DirectoryExists(directory) |
55 | then |
||
56 | start_traverse(directory) |
||
57 | else |
||
37 | - | 58 | Usage('ERROR: Not a directory : ' + directory) |
29 | - | 59 | else |
37 | - | 60 | Usage('ERROR: 1 argument expected'); |
29 | - | 61 | end. |