glob

List files in directories using Glob() in C

懵懂的女人 提交于 2020-12-30 03:37:46
问题 Basically, so far I have this code: #include <glob.h> #include <string.h> #include <stdio.h> # define ERROR 1 # define FAILURE -1 int main(int ac, char **av) { glob_t globlist; int i; i = 0; if (ac == 1) return (-1); else { if (glob(av[1], GLOB_PERIOD, NULL, &globlist) == GLOB_NOSPACE || glob(av[1], GLOB_PERIOD, NULL, &globlist) == GLOB_NOMATCH) return (FAILURE); if (glob(av[1], GLOB_PERIOD, NULL, &globlist) == GLOB_ABORTED) return (ERROR); while (globlist.gl_pathv[i]) { printf("%s\n",

Why does Perl's glob() function always return a file name when given a string with no globbing characters?

一笑奈何 提交于 2020-07-20 07:15:46
问题 I gave a list of globs and one string to Perl's glob function. The globs were treated as expected but the string is always found. For example: $ ls foo $ perl -le '@files=glob("*bar"); print @files' ## prints nothing, as expected $ perl -le '@files=glob("bar"); print @files' bar As you can see above, the second example prints bar even though no such file exists. My first thought is that it behaves like the shell in that when no expansion is available, a glob (or something being treated as a

Why does Perl's glob() function always return a file name when given a string with no globbing characters?

三世轮回 提交于 2020-07-20 07:15:13
问题 I gave a list of globs and one string to Perl's glob function. The globs were treated as expected but the string is always found. For example: $ ls foo $ perl -le '@files=glob("*bar"); print @files' ## prints nothing, as expected $ perl -le '@files=glob("bar"); print @files' bar As you can see above, the second example prints bar even though no such file exists. My first thought is that it behaves like the shell in that when no expansion is available, a glob (or something being treated as a