Command Line

DBF Commander Professional lets you handle DBF files via the command line interface.

Thus, you can run it in MS-DOS mode with defined parameters, or in batch mode by using a *.BAT file, or by the Windows scheduler.

Below are listed the commands, with their syntax and parameters. If you need some additional commands, we can discuss it at our Forum. If they can be useful for other users too, the commands will be implemented in a future release of DBF Commander Professional.

 

SQL query on DBF file


This command is similar to SQL query execution. Syntax:

dbfcommander.exe -q <"sql_query_text">
  • <"sql_query_text"> – the SQL query text you want to execute (in double quotes).

For example:

dbfcommander.exe -q "SELECT * TOP 100 FROM 'D:\Data\orditems.dbf' WHERE unit_price>100 INTO TABLE 'D:\Data\result.dbf' ORDER BY line_no"
dbfcommander.exe -q "UPDATE 'D:\Data\employee.dbf' SET emp_id='' WHERE ALLTRIM(emp_id)='6'"
Please always use a full table name in the SQL query text, and enclose the table name in single quotes.

If the SQL query was not executed successfully, a console window with the SQL error will be shown, for example:

SQL Error

 

Run SQL file


Allows to execute set of SQL queries from a text file. Syntax:

dbfcommander.exe -qf <"path_filename.sql">
  • <"path_filename"> – the text file with SQL queries you want to run (in double quotes).

For example:

dbfcommander.exe -qf "D:\path\file.sql"

 

Import DBF file


This command is similar to the Import DBF file command. Syntax:

dbfcommander.exe -i <input_file> <output_file>
  • <input_file> – the full name of the source file to be imported.
  • <output_file> – the full name of the resulting DBF file. If the file already exists, rows will be added.

Both <input_file> and <output_file> must be enclosed in double quotes, for example:

dbfcommander.exe -i "D:\customer.xml" "D:\Data\customer.dbf"

In case of importing from a CSV file, there are more parameters:

  • [delimiter] – the delimiter to be used while import. Use '\t' to import values separated with a TAB symbol.
  • [-frfn] – use this option to use first row as field names.
  • [-srft] – second row would be used as field types.

For example:

dbfcommander.exe -i "D:\customer.csv" "D:\Data\customer.dbf" ; -frfn -srft

If this parameter is not specified, the default value (comma) will be used.

 

Import Custom XML


This command allows you to import an XML file of any structure and nesting level. For more details, see this article: Convert any XML to DBF.

 

Export DBF file


This command is similar to the Export DBF file command. Syntax:

dbfcommander.exe -e <input_file> <output_file>
  • <input_file> – the full name of the source DBF file to be exported.
  • <output_file> – the full name of the resulting file.

Both <input_file> and <output_file> must be enclosed in double quotes, for example:

dbfcommander.exe -e "D:\Data\customer.dbf" "D:\customer.xls"

In case of exporting to a CSV file, there are more possible parameters:

dbfcommander.exe -e <input_file> <output_file> [delimiter] [-frfn] [-srft] [-ansi|-utf8] [-append]
  • [delimiter] – if this parameter is not specified, the default value (comma) will be used. Use '\t' to separate values with a TAB symbol.
  • [-frfn] – use this option to add field names to the first row.
  • [-srft] – second row would contain field types.
  • [-ansi|-utf8] – exported CSV file encoding: ANSI or UTF-8.
  • [-append] – use this flag to append records to an existing CSV file; if the flag is omitted, the destination CSV file will be overwritten.

For example:

dbfcommander.exe -e "D:\Data\customer.dbf" "D:\customer.csv" ; -frfn
dbfcommander.exe -e "D:\Data\customer.dbf" "D:\customer.csv" \t -utf8 -append

 

Import from database to DBF file


This command is similar to the Import from DBMS command. Syntax:

dbfcommander.exe -idb <server_table_name> <dbf_file_name> <connection_string> [-ssc]
  • <server_table_name> – the source table in the database.
  • <dbf_file_name> – the full name of the destination DBF file the data is written to.
  • <connection_string> – the connection string (for connecting to the database).
  • -edt - deletes all rows from the destination table.
  • -ssc – this flag enables the server-side cursor; if the flag is omitted, the database cursor will be client-side (by default).

Both <dbf_file_name> and <connection_string> must be enclosed in double quotes.

In the example below, we are transferring data from the table named "customer_table" to the file "D:\Data\customer.dbf" (DBMS – MS SQL Server, server name – "test_server", database name – "test_db", login – "user1"):

dbfcommander.exe -idb customer_table "D:\Data\customer.dbf" "Provider=SQLOLEDB.1;User ID=user1;Initial Catalog=test_db;Data Source=test_server"

 

Export from DBF file to database


This command is similar to the Export to DBMS command. Syntax:

dbfcommander.exe -edb <dbf_file_name> <server_table_name> <connection_string> [-sb|-dq|-bq] [-edt] [-od] [-ssc]
  • <dbf_file_name> – the full name of the source DBF file to be exported. You can also specify a folder of DBF files to be exported (should be ended with a backslash '\'). In this case, every file will be exported to the corresponding table at the database.
  • <server_table_name> – the destination table in the database. If the table doesn't exist, please specify -create parameter in order to create the destination table automatically. In this case, you should also specify the DBMS to be used as the last parameter: -mssql, -postgre, -vfp, -mysql, -oracle, or -msaccess (see example below).
  • <connection_string> – the connection string (for connecting to the database).
  • -sb, -dq, -bq - [square brackets], "double quotes", or `back quotes` should be used for enclosing field names in.
  • -edt - deletes all rows from the destination table.
  • -od - use to omit deleted records on export process.
  • -ssc – this flag enables the server-side cursor; if the flag is omitted, the database cursor will be client-side (by default).

Both <dbf_file_name> and <connection_string> must be enclosed in double quotes.

In the example below, we are transferring data from the file "D:\Data\customer.dbf" to the table named "customer_table" (DBMS – MS SQL Server, server name – "test_server", database name – "test_db", login – "user1"):

dbfcommander.exe -edb "D:\Data\customer.dbf" customer_table "Provider=SQLOLEDB.1;User ID=user1;Initial Catalog=test_db;Data Source=test_server"

Export of a directory with DBF files to a MySQL database:

dbfcommander.exe -edb "D:\somedir\" -create "Provider=MSDASQL.1;Persist Security Info=False;Data Source=MySQL" -mysql

 

Convert DBF file


This command is similar to the Convert to command. Syntax:

dbfcommander.exe -c <file_name> <new_codepage_or_encoding>
  • <file_name> – the full name of the DBF file whose codepage (encoding) you want to change.
  • <new_codepage_or_encoding> – the new codepage number (see the codepages list), or the "utf-8" or "ansi" parameters.

For example, you can convert a DBF file from the codepage 850 International MS-DOS to 1252 Windows ANSI as follows:

dbfcommander.exe -c "D:\Data\orders.dbf" 1252

If the DBF file that you are attempting to convert is already a Windows ANSI file, a console window with the error message will open:

Convert Error

To convert a DBF file from Windows ANSI to UTF-8, use the following command:

dbfcommander.exe -c "D:\Data\orders.dbf" utf-8
If the DBF file data is encoded in MS-DOS, the result of conversion to UTF-8 will be incorrect. To properly convert an MS-DOS file to UTF-8, first convert it to the Windows encoding.

Please also note the following:

A character in the UTF-8 encoding can occupy more bytes than in ASCII or ANSI. So, not to lose any data, make sure that the width of character fields is at least twice the length of the data they contain.

To convert a DBF file from UTF-8 to Windows ANSI, use the following command:

dbfcommander.exe -c "D:\Data\orders.dbf" ansi

 

Set DBF file codepage


This command is similar to the Set codepage command. Syntax:

dbfcommander.exe -cp <file_name> <new_codepage>
  • <file_name> – the full name of the DBF file whose codepage flag you want to change.
  • <new_codepage> – the new codepage number (see the codepages list).

For example, the command

dbfcommander.exe -cp "D:\Data\products.dbf" 850

sets the file's codepage to 850 International MS-DOS.

 

Encrypt DBF file and Decrypt DBF file


This command is similar to the Encrypt and Decrypt DBF file command. Syntax:

dbfcommander.exe -enc [-dec] <input_file> <output_file> <password>
  • -enc or -dec option – the flag to encrypt or decrypt a DBF file, respectively.
  • <input_file> – the full name of the source DBF file to be encrypted or decrypted.
  • <output_file> – the full name of the resulting file.
  • <password> – the encryption/decryption password.

Examples:

dbfcommander.exe -enc "D:\DB\country.dbf" "D:\DB\country_encrypted.dbf" 123456

 

dbfcommander.exe -dec "D:\DB\country_encrypted.dbf" "D:\DB\country_decrypted.dbf" 123456

 

Change DBF format


This command is similar to changing DBF file type in the File Structure dialog window. Syntax:

dbfcommander.exe -dbase [-vfp] <file_name> [<new_codepage>]
  • -dbase – convert the file to the dBase III Plus DBF type.
  • -vfp – convert the file to the Visual FoxPro DBF type.
  • <file_name> – the full name of the source DBF file to be converted.
  • [<new_codepage>] – the new codepage of the resulting DBF file; if this parameter is omitted, the codepage will not be changed.

For example, the command

dbfcommander.exe -dbase "D:\Data\table1.dbf" 437

changes the DBF file type to dBase III Plus and converts the file data to the U.S. MS-DOS codepage.

The command

dbfcommander.exe -vfp "D:\Data\table1.dbf"

changes the DBF format of the same file to Visual FoxPro.

The behavior of this command is similar to that of Visual FoxPro's "COPY TO ..." command.

 

Generate chart images


The command is similar to creating chart using the Chart Wizard. Use the Wizard to create a chart once and you'll be given a command line for the chart at the last step. Syntax:

dbfcommander.exe -chart <"file_name"> <chart_type>
-xlabels <x_labels_field> -xvalues <x_values_field> -yvalues <y_values_field>
-saveto <"result_image_file"> [-w <image_width> -h <image_height>]
  • <"file_name"> - path and file name of the source DBF file (in double quotes).
  • <chart_type> - choose one of the following chart types: -line, -bar, -horizbar, -area, -point, -pie, -fastline, -horizline, -horizarea.
  • <x_labels_field> - character field to be used as X axis labels.
  • <x_values_field> - integer, floating, or date-time field to be used as X axis values.
  • <y_values_field> - integer, floating, or date-time field to be used as Y axis values.
  • <"result_image_file"> - path and file name of the destination PNG, JPG, GIF, or BMP image file to save the chart to.
  • -w <image_width> and -h <image_height> - optional parameters to set the chart image size in pixels. If omitted, the default size of Chart Wizard will be used.

Example:

dbfcommander.exe -chart "D:\path\source.dbf" -bar -xlabels to_country -xvalues sum_order -yvalues sum_freigh -saveto "D:\path\chart.png" -w 600 -h 400

 

Silent mode, or saving errors to a log file


In this mode, all command-line operations are done without the "Press Enter" prompt. Any errors occurring when executing the commands will be saved to a log file defined in the second parameter. The syntax is as follows:

dbfcommander.exe -silent <file_name>
  • -silent – enables the silent mode
  • <file_name> – the full file name of the error log text file. If this parameter is empty, execution of this command will disable the silent mode. If the log file <file_name> already exists, it will be replaced on each execution of the -silent command. If you launch multiple commands at once (for example, from a BAT file), any errors occurring when executing these commands will be appended to the same log file.

For instance, the command

dbfcommander.exe -silent "D:\DBF\error-log.txt"

enables the silent mode. From this point on, if there is any error during the batch command execution, it will be saved to the text file "D:\DBF\error-log.txt".

The command

dbfcommander.exe -silent ""

turns the silent mode off. From this point on, any errors will be displayed in a separate console window (by default).