Archive and Extract Example | MuleSoft Documentation
# Archive and Extract Example
The following Compression module example shows how to archive and extract files from a folder. The File Connector **List** operation lists all the files from a folder named `input`. The **Compress** operation then creates a compressed archive by generating an object with the key set to the file name and the value set to the value of the listed files. Subsequently, the **Extract** operation decompresses the archived file. Then, the **For Each** scope iterates over each extracted key/value pair and writes the file to a new output folder with the key as the new file name and the value as the corresponding extracted file content.
  1. In Studio, drag a **Scheduler** trigger to the flow.
  2. Set **Frequency** to `15` and **Time unit** to `SECONDS`.
  3. Drag the **List** operation alongside the **Scheduler** trigger.
  4. Add the connector configuration.
  5. Set **Directory path** to `input`.
  6. Drag a **Set payload** component alongside the **List** operation.
  7. Set **Value** to the following DataWeave expression:


```
output application/java
---
(0 to sizeOf(payload) - 1) as Array
reduce (index, acc={}) -&gt;
acc ++ { (payload[index].attributes.fileName): payload[index].payload}
```

  8. Drag the **Archive** operation alongside the **Set payload** component.
  9. Drag the **Extract** operation alongside the **Archive** operation.
  10. Drag the **For Each** scope.
  11. Set **Collection** to `payload`.
  12. Drag the **Write** operation into the **For Each** scope.
  13. Set **Path** to `#[output application/json--- "output/" ++ (payload pluck $$)[0]]`.
  14. Set **Content** to `[CDATA[#[output application/java --- ( payload pluck $ )[0]]]`.
  15. Drag a **Logger** component right to the **For Each** scope.
  16. Set **Message** to `output application/json --- payload`.
  17. Save and run your Mule app.


In the **Configuration XML** editor, the configuration looks like this:
```
 <flow name="archive-extract-test" >
	<scheduler doc:name="Scheduler">
		<scheduling-strategy >
			<fixed-frequency frequency="15" timeUnit="SECONDS"/>
		</scheduling-strategy>
	</scheduler>
	<file:list doc:name="List" config-ref="File_Config" directoryPath="input"/>
	<set-payload value='#[output application/java
---
(0 to sizeOf(payload) - 1) as Array
reduce (index, acc={}) -&gt;
acc ++ { (payload[index].attributes.fileName): payload[index].payload}]' doc:name="Set Payload" />
	<compression:archive doc:name="Archive" >
		<compression:archiver>
			<compression:zip-archiver />
		</compression:archiver>
	</compression:archive>
	<compression:extract doc:name="Extract" >
		<compression:extractor >
			<compression:zip-extractor />
		</compression:extractor>
	</compression:extract>
	<foreach doc:name="For Each" collection="#[dw::Core::entriesOf(payload)]">
    <file:write doc:name="Write" config-ref="File_Config" path='#[output application/json&#10;---&#10;"output/" ++ payload.key]'>
      <file:content><![CDATA[#[output application/java --- payload.value]]]></file:content>
    </file:write>
  </foreach>
	<logger level="INFO" doc:name="Logger" message="#[output application/json --- payload]"/>
 </flow>
</mule>
```

## See Also
  * Compression Module Reference
  * MuleSoft Help Center