---
title: "How to create sprite sheets from multiple folders"
description: "Follow this simple guide to learn how to automate the conversion of single sprites across numerous folders into corresponding sprite sheets."
canonical: "https://www.codeandweb.com/texturepacker/knowledgebase/creating-sprite-sheets-from-folders"
product: "texturepacker"
source: "html"
---

# How to create sprite sheets from multiple folders

Let's assume you have a main folder that contains sub folders in which you keep the sprites for your game.

E.g. like this:

*   📁 assets
    *   📁 foreground
        *   grass.png
        *   tree.png
        *   barrel.png
        *   …
    *   📁 character
        *   walk-01.png
        *   walk-02.png
        *   …

You want to create a sprite sheet for each of these folders.

The easiest way to do this is to use [TexturePacker](https://www.codeandweb.com/texturepacker.md). You can use the [MultiPack Mode](https://www.codeandweb.com/texturepacker/documentation/user-interface-overview.md#multipack) for this — but this requires a bit of configuration in the graphical user interface.

Another option is to use a bash script that scans the root folder for folders and automatically packs a sheet for each of them.

For this, install TexturePacker's [command line client](https://www.codeandweb.com/texturepacker/documentation/commandline.md) and save this as a bash script.

sheets-from-folder.sh

```bash
#!/bin/bash

# Check if the folder name argument is provided
if [ "$#" -ne 1 ]; then
    echo "Usage: $0 root_folder_name"
    exit 1
fi

# Root folder
ROOT_FOLDER=$1

# Check if the root folder exists
if [ ! -d "$ROOT_FOLDER" ]; then
    echo "Root folder '$ROOT_FOLDER' does not exist!"
    exit 1
fi

# Iterate over immediate subdirectories
for SUBDIR in "$ROOT_FOLDER"/*; do
    if [ -d "$SUBDIR" ]; then
        BASENAME=$(basename "$SUBDIR")
        echo "Processing $SUBDIR ..."
        TexturePacker --sheet "${BASENAME}.png" --data "${BASENAME}.json" "$SUBDIR"
    fi
done

echo "Done"
```

Adjust the highlighted line to contain the parameters you want to use for the sprite sheet creation. See the [Texture Settings](https://www.codeandweb.com/texturepacker/documentation/texture-settings.md) in the documentation for more details.

Give the script execution rights:

```bash
chmod u+x sheets-from-folder.sh
```

Assuming, your files are all in the _assets_ folder, create and update your sprite sheets using this command:

```bash
./sheets-from-folder.sh assets
```

TexturePacker checks for changes in the folders and only update the sprite sheets when files were added, removed or changed.

## Structured data

```json
{
  "@context": "https://schema.org",
  "@type": "TechArticle",
  "headline": "How to create sprite sheets from multiple folders"
}
```
