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

 

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.

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 is one more parameter: a delimiter. For example:

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

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 is one more parameter: a delimiter. For example:

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

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

 

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).
  • -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> [-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.
  • -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.

 

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).