WRITEFILE        Write string to specified text file

Top  Previous  Next

Syntax:

WRITEFILE

[ file name ] [ string_out ] [ /options ]

Arguments:

[ file name ]

A variable or string to specify the file name to write to; if no path is defined Robo-FTPs working folder is used; if the file does not exist, it is created.

 

[ string_out ]

A variable or string to be written to the file.

Options:

/append

Append the string to the existing file.

 

/hex

Interpret the output string as a hexadecimal value rather than as standard ASCII characters.  Use this option if you need to write binary data.

 

 

This script command writes characters to the specified text file. This command is oriented toward writing a complete record of printable characters, terminated by a carriage-return/ line-feed, to a file. The scope of this command (and the READFILE command) is not to provide full function file I/O to your script files, but rather to provide temporary storage for small amounts of information for use by a script file or an external program. Use the SETPROPERTY to command to save smaller amounts of information used only within Robo-FTP scripts.

 

By default WRITEFILE either creates a new file or over-writes an existing file with what is written. You may use the /append option to add records to an existing file.

 

Note: The %crlf internal variable is available for adding additional line breaks to the output string in addition to the terminator automatically inserted by this command.

 

Consider the following example that stores user input text to a file.

 

;; write a string supplied by an operator to a file

PROMPT user_id "Enter your User ID"

WRITEFILE "user_info.txt" user_id /append

 

The WRITEFILE command may be used inside a loop to process every row in a file. The loop in the following example creates a text file that contains the names of files to be uploaded to a remote server. Only files that have been modified since yesterday are included in the list.

 

WORKINGDIR "c:\web\local\"

SET cut_off_date = %date

DATESUB cut_off 1 ;; calculate yesterday's date

GETREWIND         ;; "rewind" the file pointer (fail-safe)

:begin

GETFILE "*.txt|*.htm|*.html|*.css|*.js"

IFERROR GOTO done ;; break out of loop when no more files

IFDATE< %nextfiledate cut_off GOTO begin ;; skip old files

WRITEFILE "c:\automatic\UploadList.dat" %nextpath /append

GOTO begin         ;; loop back to get next file name

:done

 

Note: There is a corresponding loop example on the Help topic page for the READFILE command.

 

 

Related command(s): READFILE, SETPROPERTY, IFFILE, IFNFILE, MAKEFILENAME, COPY, RENAME, DELETE, APPEND, WORKINGDIR, MAKEDIR, LISTDIR

See also: %crlf