# No folder for sys.get\_save\_file (SOLVED)

**URL:** <https://forum.defold.com/t/no-folder-for-sys-get-save-file-solved/64062>\
**Category:** Questions\
**Created:** [December 9, 2019, 11:06am UTC](https://forum.defold.com/t/no-folder-for-sys-get-save-file-solved/64062 "2019-12-09T11:06:29Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![kidkiedis](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/k/c57346/32.png) [@kidkiedis](https://forum.defold.com/u/kidkiedis)\
**Post date:** [December 9, 2019, 11:06am UTC](https://forum.defold.com/t/no-folder-for-sys-get-save-file-solved/64062/1 "2019-12-09T11:06:29Z")

</div>

I’m trying to save a file with **filename = sys.get\_save\_file(“MyGame”, “profile” .. profileN)** and **sys.save(filename .. “/chars.json”, prof.character)**, but somehow it doesn’t work if there’s no folder created before it. It creates only “MyGame” folder and then gives an error _Could not write to the file C:\Users...\AppData\Roaming\MyGame\profile1/chars.json_.

How can i fix that?

Tested on Win8 and Win7.

Thank you!

---

<div class="post-metadata">

**Author:** ![dev.dashplay](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/dev.dashplay/32/19032_2.png) [@dev.dashplay](https://forum.defold.com/u/dev.dashplay)\
**Post date:** [December 9, 2019, 11:28am UTC](https://forum.defold.com/t/no-folder-for-sys-get-save-file-solved/64062/2 "2019-12-09T11:28:03Z")

</div>

This is what I use and it works:

**A LUA MODULE:**

```
local M = {}

local path = sys.get_save_file(string.gsub(sys.get_config('project.title'), '%s+', ''), 'data')
local loaded = sys.load(path)

M.table = 
{
    highscore = loaded.highscore or 0,
    mytable = mytable or {}
}

function M.save()
    sys.save(path, M.table)
end

return M

```

---

<div class="post-metadata">

**Author:** ![kidkiedis](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/k/c57346/32.png) [@kidkiedis](https://forum.defold.com/u/kidkiedis)\
**Post date:** [December 9, 2019, 11:42am UTC](https://forum.defold.com/t/no-folder-for-sys-get-save-file-solved/64062/3 "2019-12-09T11:42:57Z")

</div>

Thanks! Just got it. The problem was in that slash sign in sys.save. Changed to **sys.save(filename … “chars.json”, prof.character)** and it works.

---

<div class="post-metadata">

**Author:** ![dev.dashplay](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/dev.dashplay/32/19032_2.png) [@dev.dashplay](https://forum.defold.com/u/dev.dashplay)\
**Post date:** [December 9, 2019, 11:45am UTC](https://forum.defold.com/t/no-folder-for-sys-get-save-file-solved/64062/4 "2019-12-09T11:45:38Z")

</div>

Also remember to set a default value for each key otherwise if you want to use it later in your game and want to compare things with your save data then you might get an error like: **‘Attempt to compare a nil value’**

---

<div class="post-metadata">

**Author:** ![Mathias\_Westerdahl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mathias_westerdahl/32/228_2.png) [@Mathias\_Westerdahl](https://forum.defold.com/u/Mathias_Westerdahl)\
**Post date:** [December 9, 2019, 12:36pm UTC](https://forum.defold.com/t/no-folder-for-sys-get-save-file-solved/64062/5 "2019-12-09T12:36:12Z")

</div>

> [@kidkiedis](#):
>
> The problem was in that slash sign in sys.save

Yes, you tried to create a subfolder. The function creates a file name located in the “MyGame”.

---

<div class="post-metadata">

**Author:** ![kidkiedis](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/k/c57346/32.png) [@kidkiedis](https://forum.defold.com/u/kidkiedis)\
**Post date:** [December 9, 2019, 1:01pm UTC](https://forum.defold.com/t/no-folder-for-sys-get-save-file-solved/64062/6 "2019-12-09T13:01:09Z")

</div>

[dev.dashplay](https://forum.defold.com/u/dev.dashplay) Sry. Not sure which key you mean. =)

[Mathias\_Westerdahl](https://forum.defold.com/u/Mathias_Westerdahl)[Defold team](https://forum.defold.com/g/Defold) Can I create subfolders in runtime?

---

<div class="post-metadata">

**Author:** ![Mathias\_Westerdahl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mathias_westerdahl/32/228_2.png) [@Mathias\_Westerdahl](https://forum.defold.com/u/Mathias_Westerdahl)\
**Post date:** [December 9, 2019, 1:07pm UTC](https://forum.defold.com/t/no-folder-for-sys-get-save-file-solved/64062/7 "2019-12-09T13:07:12Z")

</div>

I don’t think you can using `sys.get_save_file()` no. Perhaps using the Lua `io` module?  
What’s the use case/benefit of having multiple folders in the app folder?

---

<div class="post-metadata">

**Author:** ![kidkiedis](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/k/c57346/32.png) [@kidkiedis](https://forum.defold.com/u/kidkiedis)\
**Post date:** [December 9, 2019, 1:32pm UTC](https://forum.defold.com/t/no-folder-for-sys-get-save-file-solved/64062/8 "2019-12-09T13:32:42Z")

</div>

Well, guess we’ll figure it out later. Now I’m super happy that we’ve made a solid demo from scratch in just a 3 months. Absolutely astonishing results with Defold. =)

---

<div class="post-metadata">

**Author:** ![Chung\_Xa](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/chung_xa/32/34470_2.png) [@Chung\_Xa](https://forum.defold.com/u/Chung_Xa)\
**Post date:** [June 21, 2024, 3:22pm UTC](https://forum.defold.com/t/no-folder-for-sys-get-save-file-solved/64062/9 "2024-06-21T15:22:47Z")

</div>

I still need subfolders. Is there any api that I can use to create subfolders?

---

<div class="post-metadata">

**Author:** ![WhiteBoxDev](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/whiteboxdev/32/36080_2.png) [@WhiteBoxDev](https://forum.defold.com/u/WhiteBoxDev)\
**Post date:** [June 21, 2024, 3:42pm UTC](https://forum.defold.com/t/no-folder-for-sys-get-save-file-solved/64062/10 "2024-06-21T15:42:09Z")

</div>

LFS Extension: [GitHub - britzl/defold-lfs: LuaFileSystem port to a Defold native extension · GitHub](https://github.com/britzl/defold-lfs)

I also built a library for saving and loading data and auto-building subfolder paths, so I could share that if needed.

---

<div class="post-metadata">

**Author:** ![Chung\_Xa](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/chung_xa/32/34470_2.png) [@Chung\_Xa](https://forum.defold.com/u/Chung_Xa)\
**Post date:** [June 21, 2024, 3:57pm UTC](https://forum.defold.com/t/no-folder-for-sys-get-save-file-solved/64062/11 "2024-06-21T15:57:05Z")

</div>

Thanks, right now I just want it to create a subfolder for caching files
