File Query CLI Help

Copyright © 2008 WorldTree Software. www.WorldTreeSoftware.com

File Query is a command line interface you can use to search for files on your computer. You specify search criteria using File Query Language (FQL), which is similar to SQL. This allows you to specify complex search criteria to find exactly what you're looking for.

Quick Start

There are two ways to run File Query. You can have it execute one query or go into shell mode and execute multiple queries from the command line. To execute one query open a command prompt and execute the application with a file query. The below lists all files in the current directory and all subdirectories that have the "exe" extension.

fquery select from . where ext=exe

To go into shell mode just start fquery.exe with no parameters. You will then see a "FQ>" prompt. It is now waiting for you to enter a command. Enter the same command as above.

FQ>select from . where ext=exe

To exit fquery type quit on the command line.

File Query Command Mode

Command mode allows you to execute a number of commands in FileQuery. The main advantage of this is that you can search the results of previous queries. You have already seen how to execute an FQL query above. Here is a list of other commands available.

help or ?
Enter this to get a list of available commands.

quit
Enter this to exit the application.

cd
This command allows you to view or set the current directory. If you just type cd with no parameters it will show you the current directory. If you type in cd and a path it will change the current directory to that path.

FQ>cd c:/temp

File Query Language

The syntax of File Query Language (FQL) is similar to SQL. You specify select, from, and where clauses to define where and what to find. FQL is not case sensitive, so "select" is the same as "SELECT". A query has the following form.

SELECT [INTO $resultset|filename] FROM [-]directory[+|-]|$resultset|filename [WHERE condition [AND condition]]

SELECT
At this time there are no select parameters available. Unlike SQL there is no need to specify * after a select.

INTO
Use the into clause to store the results of a query to a result set or file. If the name begins with $ it will store the results to a result set with the specified name. Otherwise it will save the results to the specified file.

select into $exeFiles from . where ext=exe
select into c:\exeFiles.txt from . where ext=exe

Then you can use the result set or file in a subsequent query.

select from $exeFiles where name=fquery*
select from c:\exeFiles.txt where name=fquery*

Note that if you don't use the select into command to specify a name for a result set it will be stored in the $results result set. The $results result set always contains the results of the last query executed.

You can store a result set to a file using this command.

select into c:\results.txt from $results

FROM
The from clause is where specify a comma separated list of directories, result set files, and/or result sets to search in. Result set names must be prepended with the $ character. If the path is to a file it will attempt to load a result set from the file. (Result set files are created using the INTO clause.) Otherwise it will assume the path is a directory and will search all the files in the directory and it's subdirectories. The following command will search for exe files in the temp directory, the result set file foo.txt and the "barFiles" result set.

select from c:/temp, c:/foo.txt, $barFiles where ext=exe

You can append a recurse modifier to the directory name to specify if it should search subdirectories or not. If you don't specify a recurse modifier it assumes that you want to search subdirectories. Append a minus (-) sign to tell it not to search subdirectories. The following command will search for exe files only in the temp directory.

select from c:/temp- where ext=exe

You can also exclude particular directories by prepending the directory name with an exclusion modifier, the minus (-) sign. The following will search for exe files in the temp directory excluding the temp/foo directory.

select from c:/temp, -c:/temp/foo where ext=exe

WHERE
The where clause is where you specify your search filters. It is optional; if you don't specify a where clause you will get all files in the from list. Filters are separated by the "and" keyword. Note that there is no need to put quotation marks around filter values. This is a list of all the operators available: =, <>, <, <=, >, >=, IN. Not all operators are available for each filter though. See details below.

select from c:/temp where ext=exe and name=*temp*

Search Filters

The following search filters can be defined.

name
Use to filter by the name of the file. Note that the name of a file includes the extension as well. You can use simple wildcards (* or ?) or specify a regular expression. To specify a regular expression surround the expression with "re()". You can use the =, <>, and IN operators with this filter.

select from . where name = *fquery*
select from . where name = fo?bar.txt
select from . where name <> re(^.*fquery.*$)

ext
Use to filter by file extension. This is the same as using the name filter with a wildcard for the file name (name=*.txt => ext=txt). You can use the =, <>, and IN operators with this filter.

select from . where ext = txt select from . where ext in (htm, html)

contents
Use to filter by the contents of the file. It will search inside the file for the specified search string. You can specify a regular expression by surrounding the expression with "re()". You can use the =, <>, and IN operators with this filter.

select from . where contents = *help*
select from . where contents <> re(^.*help.*$)

modified
Use to filter by file last modified date. You can use all operators with this filter.

select from . where modified < 1/1/2008

size
Use to filter by file size. You can specify a size modifier of either KB, MB, or GB. If you don't specify a modifier KB is assumed. You can use all operators with this filter.

select from . where size >= 2MB

readonly
Use to filter by files marked readonly. The value can be true or false. You can use the = and <> operators with this filter.

select from . where readonly = true