Note | This command is defined in a header file and will be preprocessed by the X# preprocessor to a function call. If you disable the standard header (-nostddefs) files then this command will not be available. If you tell the compiler to use a different standard header file (-stddef ) then this command may also be not available |
Export records to a new database or text file.
COPY TO <xcTargetFile> [DATABASE <DbName> [NAME <LongName>]
[FIELDS FieldList | FIELDS LIKE <Skeleton> | FIELDS EXCEPT <Skeleton>]
[<Scope>] [FOR <lCondition>] [WHILE <lCondition> ]
[ [WITH] CDX ] | [ [WITH] PRODUCTION ] [NOOPTIMIZE]
[ [TYPE] [ FOXPLUS | FOX2X | DIF | MOD | SDF | SYLK | WK1 | WKS | WR1
| WRK | CSV | XLS | XL5 | DELIMITED [ WITH <Delim> | WITH BLANK
| WITH TAB | WITH CHARACTER <cDelim> ] ] ] [AS <nCodePage>]
TO <xcTargetFile> | The name of the target file, including an optional drive, directory, and extension. See SetDefault() and SetPath() for file searching and creation rules. The default extension for database files is determined by the RDD. For text files, it is .TXT. |
If <xcTargetFile> does not exist, it is created. If it exists, this command attempts to open the file in exclusive mode and, if successful, the file is overwritten without warning or error. If access is denied because, for example, another process is using the file, NetErr() is set to TRUE. |
DATABASE <DbName> | Specifies a database to which the new table is added. NOT SUPPORTED AT THIS MOMENT |
NAME <LongName> | Specifies a long name for the new table. Long names can contain up to 128 characters and can be used instead of short file names in the database NOT SUPPORTED AT THIS MOMENT |
FIELDS <idFieldList> | The list of fields to process. The default is all fields with the exception of memo fields, unless the command supports the MEMO clause. |
Only fields with the same names and types in both files are appended. If fields with the same name do not match in data type, a runtime error is raised. |
FIELDS LIKE <Skeleton> | You can specify field names with a wild card, such as FIELDS LIKE *name |
FIELDS EXCEPT <Skeleton> | You can exclude fields, such as for example the primary keys: FIELDS EXCEPT Id <Skeleton> supports wildcards (* and ?). For example, to replace all fields that begin with the letters A and P, use: FIELDS LIKE A*,P* |
Please note that you can combine FIELDS LIKE and FIELDS EXCEPT but you cannot combine a fields list with the LIKE and EXCEPT clauses.
WHILE <lCondition> | A condition that each visible record within the scope must meet, starting with the current record. As soon as the while condition fails, the process terminates. If no <Scope> is specified, having a while condition changes the default scope to the rest of the visible records in the file. |
<Scope> | The portion of the current database file to process. The default is all visible records. Scope is one or more clauses of: [NEXT <NEXT>] Optionally specifies the number of records to process starting with the first record of the source file. [RECORD <rec>] An optional record ID If specified, the processing begins with this data record in the source file. [<rest:REST>] The option REST specifies whether records are sequentially searched only from the current up to the last record. If a condition is specified, the option ALL is the default value. [ALL] The option ALL specifies that all records from the source file are imported. This is the default setting. |
FOR <lCondition> | A condition that each visible record within the scope must meet in order to be processed. If a record does not meet the specified condition, it is ignored and the next visible record is processed. If no <Scope> or WHILE clause is specified, having a for condition changes the default scope to all visible records. |
DELIMITED WITH <Delim> | Indicates that character fields are separated by a character other than the quotation mark. |
DELIMITED WITH BLANK | Specifies files that contain fields separated by spaces instead of commas. |
DELIMITED WITH TAB | Specifies files that contain fields separated by tabs rather than commas. |
WITH CHARACTER <cDelim> | Specifies files that contain fields all enclosed by the character specified with Delimiter. If Delimiter is a semicolon (the character used in Visual FoxPro to indicate command line continuation), enclose the semicolon in quotation marks. You can also specify the BLANK and TAB keywords for Delimiter. The WITH Delimiter clause can be combined with the WITH CHARACTER clause. |
TYPE | Specifies the file type if the file you create is not a XBase table. Although you must specify a file type, you do not need to include the TYPE keyword. |
From the various types that FoxPro allows only the following ones are supported in X# at this moment: |
SDF An SDF file is an ASCII text file in which records have a fixed length and end with a carriage return and line feed. Fields are not delimited. The file name extension is assumed to be .txt for SDF files. |
CSV A comma separated value file. A CSV file has field names as the first line in the file; the field names are ignored when the file is imported.
The file name extension is assumed to be .csv for CSV files.
FOXPLUS Visual FoxPro memo files have a different structure than FoxBASE memo files.
If your source table contains a memo field, include the FOXPLUS clause to create a table that can be used in FoxBASE+.
The Visual FoxPro memo field cannot contain binary data because FoxBASE+ does not support binary data in memo fields.
FOX2X Creates a new table that can be opened in earlier versions of FoxPro (versions 2.0, 2.5, and 2.6). |
OTHER NOT SUPPORTED AT THIS MOMENT |
AS <nCodePage> | Specifies the codepage to use for the target file. NOT SUPPORTED AT THIS MOMENT |
Deleted records: If SetDeleted() is FALSE, deleted records in the source file are copied to <xcTargetFile> where they retain their deleted status.
Visibility: If SetDeleted() is TRUE, however, deleted records are not visible and are, therefore, not processed. Similarly, filtered records (with DbSetFilter() or a conditional controlling order) are not processed.
This example demonstrates copying to another database file:
USE sales NEW
COPY TO temp
This example demonstrates the layout of an SDF file with four fields, one for each data type:
USE testdata NEW
COPY NEXT 1 TO temp SDF
TYPE temp.txt
// Result: Character 12.0019890801T
The next example demonstrates the layout of a DELIMITED file:
COPY NEXT 1 TO temp DELIMITED
TYPE temp.txt
// Result: "Character",12.00,19890801,T
Finally, this example demonstrates the layout of a DELIMITED file WITH a different delimiter:
COPY NEXT 1 TO temp DELIMITED WITH '
TYPE temp.txt
// Result: 'Character',12.00,19890801,T
XSharp.RT.DLL
APPEND FROM, COPY FILE, COPY STRUCTURE, DbCopy(), DbCopyDelim(), DbCopySDF(), RDDSetDefault(), SetDefault(), SetPath(), SetDeleted()