# Where should a desktop app store its settings, data and cache on Windows and macOS?
Source: https://ruststudio.org/community/t/251/where-should-a-desktop-app-store-its-settings-data-and-cache-on-windows-and
Author: Ruststudio Team (staff) | Published: 2026-12-05 | Updated: 2026-12-05 | Checked with: rustc 1.93.0, Windows 11, dirs 6.0.0; compiled and run on Windows (output below is real, with the home folder shown as ~). The macOS paths come from the dirs documentation and were not run on a Mac.
Category: Help and questions | Kind: FAQ | Tags: settings, paths, windows, macos, dirs | Views: 0

## Short answer
Use the per-user folders the system provides, not the program's own folder. The dirs crate returns them: on Windows the AppData Roaming and Local folders, on macOS Library Application Support and Library Caches. Put a folder named after your app inside, and keep settings, data and cache apart.

## Answer
## Answer
A program should not write next to its executable. On Windows an app installed under `Program Files` usually cannot write there without administrator rights, and on macOS an app bundle should stay unchanged (changing it can break its code signature). Every user also needs their own settings.

Both systems define per-user folders for this. The `dirs` crate asks the system for them, so you do not hard-code paths. The table is from the crate's documentation (read 2026-12-05); the Windows column was also run, see below.

| `dirs` function | Windows | macOS | Use it for |
|---|---|---|---|
| `config_dir()` | `AppData\Roaming` (the Known Folder RoamingAppData) | `~/Library/Application Support` | settings the user would want on another PC (on Windows this folder can roam with a domain profile) |
| `config_local_dir()` | `AppData\Local` | `~/Library/Application Support` | settings tied to this machine |
| `data_dir()` / `data_local_dir()` | `AppData\Roaming` / `AppData\Local` | `~/Library/Application Support` | documents, databases, downloaded content |
| `cache_dir()` | `AppData\Local` | `~/Library/Caches` | things you can rebuild; the user or the system may delete them |

In every case you add **your own subfolder**: `config_dir().join("MyApp")`. Never write directly into the shared folder.

This program prints each folder relative to the home folder, so the output does not contain a user name:

```rust title=src/main.rs
fn main() {
    let home = dirs::home_dir().expect("no home folder");
    // Print each folder relative to the home folder, so the output does not depend on the user name.
    let show = |name: &str, p: Option<std::path::PathBuf>| match p {
        Some(p) => match p.strip_prefix(&home) {
            Ok(rel) => println!("{name:<16} ~\\{}", rel.display()),
            Err(_) => println!("{name:<16} (outside the home folder)"),
        },
        None => println!("{name:<16} none"),
    };
    show("config_dir", dirs::config_dir());
    show("config_local_dir", dirs::config_local_dir());
    show("data_dir", dirs::data_dir());
    show("data_local_dir", dirs::data_local_dir());
    show("cache_dir", dirs::cache_dir());
}
```

```text
config_dir       ~\AppData\Roaming
config_local_dir ~\AppData\Local
data_dir         ~\AppData\Roaming
data_local_dir   ~\AppData\Local
cache_dir        ~\AppData\Local
```

(The `~\` is the program's own formatting; the real folders start with the full path of the user's home folder.)

Each function returns an `Option`: handle `None` (for example by running without saved settings) instead of `unwrap`.

## Common mistakes
- Writing to the current directory. It is whatever folder the program was started from (see the thread on the executable's folder).
- Putting a cache in the settings folder. Backups and roaming profiles would then carry data that is only a cache.
- Storing passwords or tokens in a plain settings file. Use the system's credential store through a crate for it, or ask for the secret again.

## Related questions
### Does a `dirs` path include my app's name?
No. It is the shared folder for all apps; you add the subfolder.

### What about Linux?
`dirs` follows the XDG folders there (`~/.config`, `~/.local/share`, `~/.cache`) according to its documentation. Not run here.

## Sources
- dirs crate documentation, platform table: https://docs.rs/dirs/6.0.0/dirs/ (read 2026-12-05)
- Microsoft, Known Folders: https://learn.microsoft.com/windows/win32/shell/known-folders (read 2026-12-05)
- Apple, File System Programming Guide, library directories: https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/MacOSXDirectories/MacOSXDirectories.html (read 2026-12-05)
