Last change
on this file since f40a309 was 3ae31e9, checked in by Thomas Lopatic <thomas@…>, 7 years ago |
Imported original source code.
|
-
Property mode
set to
100755
|
File size:
903 bytes
|
Line | |
---|
1 | #include "stdio.h"
|
---|
2 | #include "dir.h"
|
---|
3 |
|
---|
4 | extern int alphasort();
|
---|
5 |
|
---|
6 | char pattern[80];
|
---|
7 |
|
---|
8 | int
|
---|
9 | select(dirptr)
|
---|
10 | struct direct *dirptr;
|
---|
11 | {
|
---|
12 | return(fmatch(dirptr->d_name, pattern));
|
---|
13 | }
|
---|
14 |
|
---|
15 | main(argc, argv)
|
---|
16 | int argc;
|
---|
17 | char *argv[];
|
---|
18 | {
|
---|
19 | struct direct **namelist;
|
---|
20 | int num, ii;
|
---|
21 | char *ptr, *strrchr();
|
---|
22 |
|
---|
23 | if(argc < 2) {
|
---|
24 |
|
---|
25 | argv[1] = ".";
|
---|
26 | strcpy(pattern, "*.*");
|
---|
27 |
|
---|
28 | } else if((ptr = strrchr(argv[1], '/')) == NULL) {
|
---|
29 |
|
---|
30 | strcpy(pattern, argv[1]);
|
---|
31 | argv[1] = ".";
|
---|
32 |
|
---|
33 | } else {
|
---|
34 |
|
---|
35 | strcpy(pattern, ptr + 1);
|
---|
36 | *ptr = '\0';
|
---|
37 | }
|
---|
38 |
|
---|
39 | if((num = scandir(argv[1], &namelist, select, alphasort)) <= 0) {
|
---|
40 |
|
---|
41 | fprintf(stderr, "dirtest2: ");
|
---|
42 | perror(argv[1]);
|
---|
43 | exit(1);
|
---|
44 | }
|
---|
45 |
|
---|
46 | if(num == 0) {
|
---|
47 |
|
---|
48 | printf("%s: Not found\n", pattern);
|
---|
49 | exit(1);
|
---|
50 | }
|
---|
51 |
|
---|
52 | for(ii = 0; ii < num; ii++) {
|
---|
53 |
|
---|
54 | printf("%s, size = %ld\n",
|
---|
55 | namelist[ii]->d_name, namelist[ii]->d_size);
|
---|
56 | }
|
---|
57 |
|
---|
58 | freedir(namelist, num);
|
---|
59 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.