# \[command\] Batch save files contained in a folder

**URL:** https://community.aseprite.org/t/command-batch-save-files-contained-in-a-folder/2092
**Category:** Help
**Created:** [October 10, 2018, 1:05pm UTC](https://community.aseprite.org/t/command-batch-save-files-contained-in-a-folder/2092 "2018-10-10T13:05:17Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![J-A\_C](https://community.aseprite.org/user_avatar/community.aseprite.org/j-a_c/32/11133_2.png) [@J-A\_C](https://community.aseprite.org/u/J-A_C)
#### Post date: [October 10, 2018, 1:05pm UTC](https://community.aseprite.org/t/command-batch-save-files-contained-in-a-folder/2092/1 "2018-10-10T13:05:17Z")

</div>

Hi all,

I’m executing this command in a bat file :

@set ASEPRITE=“C:\Program Files (x86)\Steam\steamapps\common\Aseprite\aseprite.exe”  
%ASEPRITE% -b D:\PATH\_LOAD\sprite.ase --save-as D:\PATH\_SAVE{tag}\_01.png

But I’d like to execute it for all the \*.ase files located in my PATH\_LOAD folder (including subfloder).  
I don’t know much about CMD features, I gave some FOR logic a go without any success.

Could someone give me a hand on that one ?

Cheers

---

<div class="post-metadata">

### Author: ![dacap](https://community.aseprite.org/user_avatar/community.aseprite.org/dacap/32/10_2.png) [@dacap](https://community.aseprite.org/u/dacap)
#### Post date: [October 10, 2018, 2:08pm UTC](https://community.aseprite.org/t/command-batch-save-files-contained-in-a-folder/2092/2 "2018-10-10T14:08:01Z")

</div>

You can try some of [these solutions](https://stackoverflow.com/a/180749), anyway I would recommend you to use a Bash script which are easier to program (generally all [Git distributions for Windows](https://gitforwindows.org/) include some kind of Bash interpreter), where you can do something like:

```
aseprite=“C:/Program Files (x86)/Steam/steamapps/common/Aseprite/aseprite.exe”
for file in D:/PATH_LOAD/*.ase ; do
  $aseprite -b $file --save-as D:/PATH_SAVE/{title}_{tag}_01.png
done
```

---

<div class="post-metadata">

### Author: ![J-A\_C](https://community.aseprite.org/user_avatar/community.aseprite.org/j-a_c/32/11133_2.png) [@J-A\_C](https://community.aseprite.org/u/J-A_C)
#### Post date: [October 10, 2018, 2:38pm UTC](https://community.aseprite.org/t/command-batch-save-files-contained-in-a-folder/2092/3 "2018-10-10T14:38:25Z")

</div>

Thanks, I’ve seen the solutions you sent me. That’s what I failed to use.  
Do the Bash script is usable in a bat file ?

---

<div class="post-metadata">

### Author: ![dacap](https://community.aseprite.org/user_avatar/community.aseprite.org/dacap/32/10_2.png) [@dacap](https://community.aseprite.org/u/dacap)
#### Post date: [October 10, 2018, 2:41pm UTC](https://community.aseprite.org/t/command-batch-save-files-contained-in-a-folder/2092/4 "2018-10-10T14:41:43Z")

</div>

> [@J-A\_C](#):
>
> Do the Bash script is usable in a bat file ?

You will need an extra .sh script and call it with a bash interpreter from the .bat file:

```
"C:\some place where bash is located\bash.exe" other_script.sh

```

Generally I make all scripts directly on bash language and then call them from the command line using `bash script name` (without a .bat, but you can use a .bat to double-click it from the Windows Explorer)

---

<div class="post-metadata">

### Author: ![J-A\_C](https://community.aseprite.org/user_avatar/community.aseprite.org/j-a_c/32/11133_2.png) [@J-A\_C](https://community.aseprite.org/u/J-A_C)
#### Post date: [October 10, 2018, 3:20pm UTC](https://community.aseprite.org/t/command-batch-save-files-contained-in-a-folder/2092/5 "2018-10-10T15:20:05Z")

</div>

Thanks, you’re fast 🙂

That’s a good idea. I’m trying to do as in your example but I don’t know why it doesn’t work.  
I made a script.sh file with that inside :

aseprite=“C:/Program Files (x86)/Steam/steamapps/common/Aseprite/aseprite.exe”  
for file in D:/PATH\_LOAD/\*.ase ; do  
$aseprite -b $file --save-as D:/PATH\_SAVE/{title}\_{tag}\_01.png  
end

But nothing seems to happen. I don’t get what I’m doing wrong.

---

<div class="post-metadata">

### Author: ![dacap](https://community.aseprite.org/user_avatar/community.aseprite.org/dacap/32/10_2.png) [@dacap](https://community.aseprite.org/u/dacap)
#### Post date: [October 10, 2018, 3:38pm UTC](https://community.aseprite.org/t/command-batch-save-files-contained-in-a-folder/2092/6 "2018-10-10T15:38:52Z")

</div>

How are you executing the script? What is the output in the console/terminal?

---

<div class="post-metadata">

### Author: ![J-A\_C](https://community.aseprite.org/user_avatar/community.aseprite.org/j-a_c/32/11133_2.png) [@J-A\_C](https://community.aseprite.org/u/J-A_C)
#### Post date: [October 10, 2018, 3:44pm UTC](https://community.aseprite.org/t/command-batch-save-files-contained-in-a-folder/2092/7 "2018-10-10T15:44:39Z")

</div>

I tried to run it through the Git Bash command prompt. Here’s what happened. (I’m pasting the whole thing)

A@DESKTOP-EM60RBJ MINGW64 ~  
$ aseprite=“C:/Program Files (x86)/Steam/steamapps/common/Aseprite/aseprite.exe”

A@DESKTOP-EM60RBJ MINGW64 ~  
$ for file in D:/PATH\_LOAD/\*.ase ; do

> $aseprite -b $file --save-as D:/PATH\_LOAD/{title}\_{tag}\_01.png  
> end

Then, it just stayed there doing nothing else.

And I also tried to put it in a sh file and launch it by double clicking on it (I’m improvising here…).  
I’m very new to this.

---

<div class="post-metadata">

### Author: ![dacap](https://community.aseprite.org/user_avatar/community.aseprite.org/dacap/32/10_2.png) [@dacap](https://community.aseprite.org/u/dacap)
#### Post date: [October 10, 2018, 4:29pm UTC](https://community.aseprite.org/t/command-batch-save-files-contained-in-a-folder/2092/8 "2018-10-10T16:29:33Z")

</div>

> [@J-A\_C](#):
>
> Then, it just stayed there doing nothing else.

My mistake, the final word is not `end`, is `done` (editing my original reply right now).

---

<div class="post-metadata">

### Author: ![J-A\_C](https://community.aseprite.org/user_avatar/community.aseprite.org/j-a_c/32/11133_2.png) [@J-A\_C](https://community.aseprite.org/u/J-A_C)
#### Post date: [October 10, 2018, 4:42pm UTC](https://community.aseprite.org/t/command-batch-save-files-contained-in-a-folder/2092/9 "2018-10-10T16:42:21Z")

</div>

Thanks,  
it went a little bit further this time.  
but it ended with this :

bash: C:/Program: No such file or directory

And it did nothing.

---

<div class="post-metadata">

### Author: ![dacap](https://community.aseprite.org/user_avatar/community.aseprite.org/dacap/32/10_2.png) [@dacap](https://community.aseprite.org/u/dacap)
#### Post date: [October 10, 2018, 4:45pm UTC](https://community.aseprite.org/t/command-batch-save-files-contained-in-a-folder/2092/10 "2018-10-10T16:45:45Z")

</div>

Try using `"$aseprite"` to call Aseprite.

---

<div class="post-metadata">

### Author: ![J-A\_C](https://community.aseprite.org/user_avatar/community.aseprite.org/j-a_c/32/11133_2.png) [@J-A\_C](https://community.aseprite.org/u/J-A_C)
#### Post date: [October 10, 2018, 4:55pm UTC](https://community.aseprite.org/t/command-batch-save-files-contained-in-a-folder/2092/11 "2018-10-10T16:55:49Z")

</div>

Thank you for taking the time. That’s nice to take care of newbie 🙂

I tried using $aseprite instead of the whole path, I tried to add it in front of the path… I tried several other thing, but this is what I got most of the time :

bash: -batch: command not found

---

<div class="post-metadata">

### Author: ![dacap](https://community.aseprite.org/user_avatar/community.aseprite.org/dacap/32/10_2.png) [@dacap](https://community.aseprite.org/u/dacap)
#### Post date: [October 10, 2018, 4:58pm UTC](https://community.aseprite.org/t/command-batch-save-files-contained-in-a-folder/2092/12 "2018-10-10T16:58:40Z")

</div>

Let me copy a new version of the script:

```bash
aseprite=“C:/Program Files (x86)/Steam/steamapps/common/Aseprite/aseprite.exe”
for file in D:/PATH_LOAD/*.ase ; do
  "$aseprite" -b $file --save-as D:/PATH_SAVE/{title}_{tag}_01.png
done

```

(Sorry for the back and forth about this but I’m not on Windows right now to give a try 😭)

---

<div class="post-metadata">

### Author: ![J-A\_C](https://community.aseprite.org/user_avatar/community.aseprite.org/j-a_c/32/11133_2.png) [@J-A\_C](https://community.aseprite.org/u/J-A_C)
#### Post date: [October 10, 2018, 5:14pm UTC](https://community.aseprite.org/t/command-batch-save-files-contained-in-a-folder/2092/13 "2018-10-10T17:14:58Z")

</div>

Don’t be sorry, you’ve been very helpful (even in the past).  
It works great now. Thanks a lot.

Now I’m trying to “include” it inside of my bat file but I’m kinda stuck.  
I tried to add what you suggested earlier :

“C:\Program Files\Git\git-bash.exe” script.sh

and added what we’ve been muddling through in the script.sh.

But nothing happened.

---

<div class="post-metadata">

### Author: ![dacap](https://community.aseprite.org/user_avatar/community.aseprite.org/dacap/32/10_2.png) [@dacap](https://community.aseprite.org/u/dacap)
#### Post date: [October 10, 2018, 6:29pm UTC](https://community.aseprite.org/t/command-batch-save-files-contained-in-a-folder/2092/14 "2018-10-10T18:29:47Z")

</div>

Maybe

```
“C:\Program Files\Git\git-bash.exe” -c script.sh

```

could work, but I’m not sure, or

```
“C:\Program Files\Git\git-bash.exe” -c "bash script.sh"
```

---

<div class="post-metadata">

### Author: ![J-A\_C](https://community.aseprite.org/user_avatar/community.aseprite.org/j-a_c/32/11133_2.png) [@J-A\_C](https://community.aseprite.org/u/J-A_C)
#### Post date: [October 10, 2018, 9:04pm UTC](https://community.aseprite.org/t/command-batch-save-files-contained-in-a-folder/2092/15 "2018-10-10T21:04:02Z")

</div>

I ended up doing the script with bash only. It seems indeed easier to work with.  
Right now I’m trying to make an if statement inside a for loop to batch all the \*.ase of a folder except for one that I want to save in a different manner.

Does it look remotely like something that could work at some point ?

for file in D:/00\_TAKROG/SPRITES/CHARACTERS/\*.ase ; do  
if [${file: -4} == “items.ase”]; then  
“$aseprite” -b --split-layers D:/00\_TAKROG/ATLAS\_UNIT\_AND\_DOODADS/items.ase --save-as D:/00\_TAKROG/ATLAS\_UNIT\_AND\_DOODADS/{tag}\_01.png  
fi  
done

---

<div class="post-metadata">

### Author: ![J-A\_C](https://community.aseprite.org/user_avatar/community.aseprite.org/j-a_c/32/11133_2.png) [@J-A\_C](https://community.aseprite.org/u/J-A_C)
#### Post date: [October 11, 2018, 9:35am UTC](https://community.aseprite.org/t/command-batch-save-files-contained-in-a-folder/2092/16 "2018-10-11T09:35:06Z")

</div>

We found the solution for the if statement. But something odd happens If I execute this code :

```
aseprite=“C:/Program Files (x86)/Steam/steamapps/common/Aseprite/aseprite.exe”
## "Characters" avec exception "Items"
for file in D:/00_TAKROG/SPRITES/CHARACTERS/*.ase ; do
	if [["$(basename -- "$file")" == "items.ase"]]; then
	  "$aseprite" -b --split-layers $file --save-as D:/00_TAKROG/ATLAS_UNIT_AND_DOODADS/{tag}_01.png
	else
	  "$aseprite" -b $file --save-as D:/00_TAKROG/ATLAS_UNIT_AND_DOODADS/{tag}_01.png
	fi
done

```

The `--split-layers` function is ignored.  
But I know this command works in that context because I used it in CMD, when I was using a bat file.

---

<div class="post-metadata">

### Author: ![dacap](https://community.aseprite.org/user_avatar/community.aseprite.org/dacap/32/10_2.png) [@dacap](https://community.aseprite.org/u/dacap)
#### Post date: [October 11, 2018, 12:58pm UTC](https://community.aseprite.org/t/command-batch-save-files-contained-in-a-folder/2092/17 "2018-10-11T12:58:46Z")

</div>

> [@J-A\_C](#):
>
> The `--split-layers` function is ignored.

Hi @J-A_C, I think the issue here is that the filename (`D:/00_TAKROG/ATLAS_UNIT_AND_DOODADS/{tag}_01.png`) is missing a `{layer}` part (so each layer goes to a different filename). For example:

```
"$aseprite" -b $file --save-as D:/.../{layer}{tag}_01.png

```

(The `--split-layers` is automatically done when the filename specified in `--save-as` contains `{layer}`)

---

<div class="post-metadata">

### Author: ![J-A\_C](https://community.aseprite.org/user_avatar/community.aseprite.org/j-a_c/32/11133_2.png) [@J-A\_C](https://community.aseprite.org/u/J-A_C)
#### Post date: [October 11, 2018, 1:53pm UTC](https://community.aseprite.org/t/command-batch-save-files-contained-in-a-folder/2092/18 "2018-10-11T13:53:00Z")

</div>

YES ! That works 😃  
Thank you so much !

---

<div class="post-metadata">

### Author: ![dacap](https://community.aseprite.org/user_avatar/community.aseprite.org/dacap/32/10_2.png) [@dacap](https://community.aseprite.org/u/dacap)
#### Post date: [October 11, 2018, 1:53pm UTC](https://community.aseprite.org/t/command-batch-save-files-contained-in-a-folder/2092/19 "2018-10-11T13:53:55Z")

</div>

You’re welcome! 😊

---

<div class="post-metadata">

### Author: ![J-A\_C](https://community.aseprite.org/user_avatar/community.aseprite.org/j-a_c/32/11133_2.png) [@J-A\_C](https://community.aseprite.org/u/J-A_C)
#### Post date: [October 27, 2018, 11:41am UTC](https://community.aseprite.org/t/command-batch-save-files-contained-in-a-folder/2092/20 "2018-10-27T11:41:28Z")

</div>

My bash script works like a charm. But there one thing I’d like to do is make my script.sh clickable, and for some reason, every command works except the one using aseprite.

Every command before

`aseprite=“C:/Program Files (x86)/Steam/steamapps/common/Aseprite/aseprite.exe”`

works, but the rest just doesn’t do anything.  
Is it even possible to do it ?

Cheers

[Next page](https://community.aseprite.org/t/command-batch-save-files-contained-in-a-folder/2092.md?page=2)
