Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Unix has a library that can perform file globbing operations for you. The functions and types are declared in a header called <code>glob.h</code>, so you'll need to <code>#include</code> it. If open up a terminal an open the man page for glob by typing <code>man 3 glob</code> you'll get all of the information you need to know to use the functions.</p> <p>Below is an example of how you could populate an array the files that match a globbing pattern. When using the <code>glob</code> function there are a few things you need to keep in mind.</p> <ol> <li>By default, the <code>glob</code> function looks for files in the current working directory. In order to search another directory you'll need to prepend the directory name to the globbing pattern as I've done in my example to get all of the files in <code>/bin</code>.</li> <li>You are responsible for cleaning up the memory allocated by <code>glob</code> by calling <code>globfree</code> when you're done with the structure.</li> </ol> <p>In my example I use the default options and no error callback. The man page covers all of the options in case there's something in there you want to use. If you're going to use the above code, I'd suggest adding it as a category to <code>NSArray</code> or something like that.</p> <pre><code>NSMutableArray* files = [NSMutableArray array]; glob_t gt; char* pattern = "/bin/*"; if (glob(pattern, 0, NULL, &amp;gt) == 0) { int i; for (i=0; i&lt;gt.gl_matchc; i++) { [files addObject: [NSString stringWithCString: gt.gl_pathv[i]]]; } } globfree(&amp;gt); return [NSArray arrayWithArray: files]; </code></pre> <p>Edit: I've created a gist on github that contains the above code in a category called <a href="http://gist.github.com/293959" rel="noreferrer">NSArray+Globbing</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload