=============================== Using the built-in FileIO Tasks =============================== FireWorks comes with several built-in tasks for performing file I/O (writing, moving, and deleting files). FileWriteTask ============== The *FileWriteTask* is a simple way to write files (a more powerful version based on templating is the :doc:`TemplateWriterTask `). Required parameters ------------------- * files_to_write: ([{filename:(str), contents:(str)}]) - this is a list of dictionaries. each dictionary must have a filename (string) and contents (str). The contents are written to the corresponding filename. Optional parameters ------------------- * dest: (str) - the directory in which to write all the files (default is current working directory) FileDeleteTask ============== The *FileDeleteTask* lets you delete one or more files. Required parameters ------------------- * files_to_delete: ([(str)]) - a list of Strings corresponding to the filenames to delete Optional parameters ------------------- * dest: (str) - the directory in which to delete all the files (default is current working directory) FileTransferTask ================ The FileTransferTask is a built-in Firetask for moving and copying files, perhaps to a remote server. Its usage is straightforward: * a ``files`` key that contains a list of files to move or copy * additional options control how directory names are interpreted, how to perform the move/copy, and what to do in case of errors An example of a Firework that copies two files, ``file1.txt`` and ``file2.txt``, to the home directory looks as follows:: spec: _tasks: - _fw_name: FileTransferTask files: - src: file1.txt dest: ~/file1.txt - src: file2.txt dest: ~/file2.txt mode: copy In Python code, the same task would be defined as:: firetask1 = FileTransferTask({'files': [{'src': 'file1.txt', 'dest': '~/file1.txt'}, {'src': 'file2.txt', 'dest': '~/file2.txt'}], 'mode': 'copy'}) The ``files`` parameter *must* be specified, and is an array of dictionaries with ``src`` and ``dest`` keys. The default mode of operation is to move files from the source to destination; by changing the ``mode`` to copy, we will copy the files instead. Note that you can put as many files (or directories) in the ``files`` list as you want; the same ``mode`` will be applied to all of them. If you want to move some files and copy others, you'd need to include two different ``FileTransferTask``s in your Firework. A more compact representation for File Transfers can be given if several files are being moved/copied to the same directory:: spec: _tasks: - _fw_name: FileTransferTask dest: dest_dir files: - file1.txt - file2.txt mode: copy In Python code, this representation would be defined as:: firetask1 = FileTransferTask({'files': ['file1.txt', 'file2.txt'], 'dest':'dest_dir', 'mode': 'copy'}) An example of the FileTransferTask in action is given in the :doc:`Firetask tutorial `. FileTransferTask Options ------------------------ Below are the various options that can be set for the FileTransferTask. **mode** The potential values are: * *move* - move a file or directory * *copy* - copy a file/dir (including permissions) but do not include metadata * *copy2* - copy a file/dir (including permissions); also include metadata * *copytree* - recursively copy an entire directory copy * *copyfile* - copy the contents of a file into another file (no metadata) * *rtransfer* - do a remote transfer (this is covered later in this doc) .. note:: With the exception of **rtransfer**, ``FileTransferTask`` is using Python's *shutil* module to do the move/copy. You can read more about these modes in `Python's *shutil* docs