# Using File Globs

If you want users to be able to pass file globbing patterns to your command, set a type of `Globber` for the argument.

```
/**
* @path.hint file or directory to interact with.
**/
function run( required Globber path )  { }
```

Even though the user types a string, CommandBox will hand you a CFC instance that's preloaded with the matching paths and has some nice methods to help you interact with the matching paths. The Globber object lazy loads the matches, which gives you time to affect the pattern or even the sort if you wish prior to the file system actually being hit.

## Globber.count()

Use the `count()` method to get the total number of paths matched on the file system.

```
function run( required Globber path ) {
  print.line( path.count() & ' files affected!' );
}
```

## Globber.apply( ... )

The easiest way to apply some processing to each of the file paths found is by passing a closure to the `apply()` method. The closure will be executed once for each result.

```
function run( required Globber path ) {
  path.apply( function( thisPath ){
    print.line( 'Processing file ' & thisPath );
  } );
}
```

## Globber.matches()

To get the raw results back, use the `matches()` method.

### Globber.asQuery()

If you want to get the results back as a query object, use the `asQuery()` method and then you can loop over them yourself. The query contents match what comes back from `directoryList()`.

```
function run( required Globber path ) {
var myQry = path
  .asQuery()
  .matches();
}
```

### Globber.asArray()

If you want to get the results back as an array, use the `asArray()` method and then you can loop over them yourself.

```
function run( required Globber path ) {
var myArr = path
  .asArray()
  .matches();
}
```

## Globber.withSort( ... )

Affect the order that the results come back by setting a sort. The sort follows the same pattern as the directoryList() function, which means it can be a comma-delimited list of columns to sort on.

```
function run( required Globber path ) {
var myQry = path
  .asQuery()
  .withSort( 'type, name' )
  .matches();
}
```

## Globber.getPattern()

To get the original globbing pattern that the user typed, use the `getPattern()` method on the Globber CFC.

```
function run( required Globber path ) {
  print.line( 'You typed ' & path.getPattern() );
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://commandbox.ortusbooks.com/4.4.0/developing-for-commandbox/commands/using-parameters/using-file-globs.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
