Last change
on this file since 636 was
49,
checked in by Sam Hocevar, 15 years ago
|
- Imported original public domain release, for future reference.
|
-
Property svn:keywords set to
Id
|
File size:
1.2 KB
|
Line | |
---|
1 | |
---|
2 | #ifdef __WATCOMC__ |
---|
3 | #include <direct.h> |
---|
4 | #else |
---|
5 | #include <dirent.h> |
---|
6 | #endif |
---|
7 | |
---|
8 | #include <stdlib.h> |
---|
9 | #include <string.h> |
---|
10 | #include "jmalloc.hpp" |
---|
11 | #include <unistd.h> |
---|
12 | |
---|
13 | void get_directory(char *path, char **&files, int &tfiles, char **&dirs, int &tdirs) |
---|
14 | { |
---|
15 | |
---|
16 | struct dirent *de; |
---|
17 | files=NULL; |
---|
18 | dirs=NULL; |
---|
19 | tfiles=0; |
---|
20 | tdirs=0; |
---|
21 | DIR *d=opendir(path); |
---|
22 | if (!d) return ; |
---|
23 | |
---|
24 | char **tlist=NULL; |
---|
25 | int t=0; |
---|
26 | char curdir[200]; |
---|
27 | getcwd(curdir,200); |
---|
28 | chdir(path); |
---|
29 | |
---|
30 | do |
---|
31 | { |
---|
32 | de=readdir(d); |
---|
33 | if (de) |
---|
34 | { |
---|
35 | t++; |
---|
36 | tlist=(char **)jrealloc(tlist,sizeof(char *)*t,"tmp file list"); |
---|
37 | tlist[t-1]=strcpy((char *)jmalloc(strlen(de->d_name)+1,"tmp file name"),de->d_name); |
---|
38 | } |
---|
39 | } while (de); |
---|
40 | closedir(d); |
---|
41 | |
---|
42 | for (int i=0;i<t;i++) |
---|
43 | { |
---|
44 | d=opendir(tlist[i]); |
---|
45 | if (d) |
---|
46 | { |
---|
47 | tdirs++; |
---|
48 | dirs=(char **)jrealloc(dirs,sizeof(char *)*tdirs,"dir list"); |
---|
49 | dirs[tdirs-1]=strcpy((char *)jmalloc(strlen(tlist[i])+1,"tmp file name"),tlist[i]); |
---|
50 | closedir(d); |
---|
51 | } else |
---|
52 | { |
---|
53 | tfiles++; |
---|
54 | files=(char **)jrealloc(files,sizeof(char *)*tfiles,"dir list"); |
---|
55 | files[tfiles-1]=strcpy((char *)jmalloc(strlen(tlist[i])+1,"tmp file name"),tlist[i]); |
---|
56 | } |
---|
57 | jfree(tlist[i]); |
---|
58 | } |
---|
59 | if (t) |
---|
60 | jfree(tlist); |
---|
61 | chdir(curdir); |
---|
62 | } |
---|
63 | |
---|
64 | |
---|
65 | |
---|
66 | |
---|
67 | |
---|
Note: See
TracBrowser
for help on using the repository browser.