When the Delete Directory Operator fails, this error is seen: The Process cannot access the file because it is being used by another process.
Directories can be used to store intermediate files as input to other model operators that are used further downstream in the model. When the model process advances beyond these directories, their file content may no longer be needed. It would be economical for disk storage to remove the directories and their content when it is no longer needed in the model.
The example model uses the 7-Zip file archive command to extract data from the .tar.gz archive (e.g. Landsat TM-USGS data format) to be used as input to other model operators. Two 7-Zip commands are executed from Command Line operators. One is used to uncompress the .tar archive file, the other is used to extract the images from the tar archive which will be used as input to other model operators. Each Command Line operator creates a folder to save content of the extraction. There may not be a need to keep both the uncompressed .tar archive file and the unarchived data images. Delete Directory operators are used to remove these data directories.
The Delete Directory operator will not delete directories containing data used in other model operators. These directories remain opened by the Spatial Modeler process until the model is completed or cancelled and the model results are cleared. These directories also cannot be deleted by the Windows Operating system until they are closed by the Spatial Modeler process.
The directory containing the uncompressed .tar archive can be deleted because the model will not use the uncompressed tar file. The directory containing the unarchived images cannot be deleted because these images are used as input to other operators in the model.
If the directory cannot be deleted, the error condition is expressed in the Messages Panel:
boost::filesystem::remove: The process cannot access the file because it is being used by another process: "e:\data\models\pathnames\del_dir\input1\lt40190361983017xxx09\LT40190361983017XXX09_B1.TIF"