getzola/zola · error

`{}` is not an empty folder (hidden files are ignored).

Error message

`{}` is not an empty folder (hidden files are ignored).

What it means

Thrown by `zola init` when the target project directory already contains files. Zola refuses to initialize into a non-empty folder to avoid overwriting user files; hidden files (dotfiles) are ignored when checking emptiness. The `--force` flag bypasses this check.

Source

Thrown at src/cmd/init.rs:78

    Ok(false)
}

// Remove the unc part of a windows path
fn strip_unc(path: &Path) -> String {
    let path_to_refine = path.to_str().unwrap();
    path_to_refine.trim_start_matches(LOCAL_UNC).to_string()
}

pub fn create_new_project(name: &str, force: bool) -> Result<()> {
    let path = Path::new(name);

    // Better error message than the rust default
    if path.exists() && !is_directory_quasi_empty(path)? && !force {
        if name == "." {
            bail!("The current directory is not an empty folder (hidden files are ignored).");
        } else {
            bail!("`{}` is not an empty folder (hidden files are ignored).", path.to_string_lossy())
        }
    }

    console::info("Welcome to Zola!");
    console::info("Please answer a few questions to get started quickly.");
    console::info("Any choices made can be changed by modifying the `zola.toml` file later.");

    let base_url = ask_url("> What is the URL of your site?", "https://example.com")?;
    let compile_sass = ask_bool("> Do you want to enable Sass compilation?", true)?;
    let search = ask_bool("> Do you want to build a search index of the content?", false)?;

    let config = CONFIG
        .trim_start()
        .replace("%BASE_URL%", &base_url)
        .replace("%COMPILE_SASS%", &format!("{compile_sass}"))
        .replace("%SEARCH%", &format!("{search}"));

    populate(path, compile_sass, &config)?;

View on GitHub (pinned to 61d3082821)

Solutions

  1. Remove or move out the existing files in the target directory, or pick a new empty directory
  2. If you intentionally want to initialize over existing content, re-run with `zola init <path> --force`
  3. Use `ls -A` to inspect the directory; note hidden files alone do not block init

Example fix

// before
$ zola init .
Error: `.` is not an empty folder (hidden files are ignored).
// after
$ ls -A   # remove/move stray visible files
$ zola init . --force   # or clean the directory first
Defensive patterns

Strategy: validation

Validate before calling

import std::fs;
fn dir_is_quasi_empty(p: &Path) -> bool {
    std::fs::read_dir(p).map(|it| it.filter_map(|e| e.ok()).all(|e| e.file_name().to_string_lossy().starts_with('.'))).unwrap_or(true)
}
if path.exists() && !dir_is_quasi_empty(path) && !force { /* abort or pass --force */ }

Type guard

fn is_init_safe(path: &Path, force: bool) -> bool { force || !path.exists() || dir_is_quasi_empty(path) }

Prevention

When it happens

Trigger: Running `zola init <path>` (or `zola init .`) when `path` exists, is not quasi-empty (contains at least one non-hidden entry), and `--force` was not passed.

Common situations: Re-running `zola init` in a directory that already has a site or stray files (e.g. README.md, .gitignore counted only if visible, templates/, content/); accidentally initializing into the wrong directory; init interrupted previously leaving files behind.

Related errors


AI-assisted analysis of getzola/zola@61d3082821 (2026-09-03). Data as JSON: /api/errors/7fa700647c69143d. Report an issue: GitHub.