The CopyDirectory service copies the source directory to a target directory. This is useful when you maintain your files in multiple places. For example, you have a temporary file server where you upload and edit the files. Once it’s done, you will move all files to the production file server. Instead of using multiple services like CreateDirectory, ReadFiles and WriteFiles, you can just use CopyDirectory to do everything. The CopySubDirectory and Override inputs give you flexibility to manage how to perform this copy.
CopyDirectory Use Examples
Basic CopyDirectory Use
In this example, we check if the source directory exists, if so we copy it to a target directory and copy all the sub directories. Since the target directory doesn’t exists, it will create new files whether the “Override” field is “True” or “False”.
The source directory has two folders inside and each folder has two files.
After the process runs, you will see TestDirectory_Copy is created with two folders inside.
If we set the CopySubDirectory field to ‘False’, it only creates the directory itself, no folders and files will be created.
CopyDirectory If Target Directory Exists
In this example, we want to copy TestDirectory to TestDirectory_Copy. Both of them already exist.
If we set CopySubDirectory to ‘False’, the service returns ‘True’, which means it runs successfully. However, there is no change in TestDirectory_Copy.
If CopySubDirectory is ‘True’, sub directories under TestDirectory will be created under TestDirectory_Copy. Since both File111 and File222 do not exist in TestDirectory_Copy, they will be created whether the “Override” field is “True” or “False”.
If before we copy the directory, one of the sub directories is the same with source directory and we set CopySubDirectory and Override to “True”.
After we run the process, the file in target directory is overridden by the file in source directory.