A JMeter run aborts with "Cannot write to ... as folder is not empty". What happened?
answer
- The destination is checked, not overwritten
- It happens before any thread starts
- There is a flag that clears the way
- Its long name mentions deleting result files
basics
~20 sThe folder given to -o already contains files. JMeter checks the report destination before the run starts and refuses rather than mix a new dashboard into an old one. The -f flag clears it first.
solid answer
~50 sWhen `-o` is present, JMeter resolves the folder and checks it up front: it may be missing (the parent must be writable), or it may exist and be empty, but any file inside it aborts the command with `Cannot write to '<path>' as folder is not empty`. If the path exists as a plain file rather than a directory, the message ends `as it is an existing file`. The check runs before the engine starts, which is deliberate — a nightly job fails in seconds instead of after two hours of load. `-f` (long form `--forceDeleteResultFile`) is the sanctioned answer: it deletes the folder named by `-o` recursively, recreates it, and also deletes the results files named by the plan's listeners before the test starts. Without `-f`, a rerun into the same folder is your problem to solve, usually by dating the path.
go deeper
Recognise the message and know the two ways out: point -o at a folder that does not exist yet, or add -f. Do not try to make JMeter overwrite the old one.
Explain that the folder must be missing or empty, that the check runs before the test starts, and that -e imposes the same rule on the results file named by -l.
Treat the early check as a feature and keep it: fail a scheduled job in seconds rather than after the load. Weigh -f, a destructive recursive delete of a path from the command line, against dated output paths.
Own the convention for where run artefacts live across teams, so that collisions are impossible by construction and no job needs a destructive flag to succeed twice in a row.
## What is being checked `-o` is not accepted blindly. JMeter turns the argument into an absolute path and runs a safety check on it before anything else happens, in both report modes — the end-of-run form and report-only generation. Three outcomes: | State of the path | Result | |---|---| | Does not exist | Accepted, as long as the parent directory is writable | | An empty directory | Accepted | | A directory with any file in it | `Cannot write to '<path>' as folder is not empty` | | An existing plain file | `Cannot write to '<path>' as it is an existing file` | The check is strict on purpose. A dashboard is a directory tree of generated pages and JSON data; writing a new one over the remains of an old one would produce a page that mixes two runs, which is far worse than a refusal. ## Why it fails early rather than late The folder is validated while the command line is being processed, before the test plan is loaded and long before the first thread starts. That ordering is the useful part: a nightly job that would have written into yesterday's folder fails in seconds. The alternative — discovering it after the load has finished — would waste the whole run, and that is exactly what happens when you do not pass `-o` at all, because then the only checks are the exporters' own laxer ones, applied at export time: the HTML exporter refuses an existing `index.html`, `content/` or `sbadmin2-*` entry in its default `bin/report-output` folder, and the JSON exporter an existing `statistics.json` in the `report-output` folder its own property names, which is relative to wherever you ran the command. ## The companion rule for the results file A run started with `-e` has a second precondition of the same shape, and the message is different enough to be confusing: ``` Results file:results.jtl is not empty ``` With `-e`, the file named by `-l` must not already exist with content. Appending a second run's samples to yesterday's file would make the dashboard describe both runs at once, so JMeter refuses instead. So a rerun of an unchanged nightly command has two ways to be rejected: the old JTL and the old report folder. ## What -f actually does `-f`, spelled `--forceDeleteResultFile` in long form, takes no argument and clears both obstacles before the test: 1. the folder named by `-o` is deleted recursively and recreated as an empty directory; 2. every results file named by a result collector in the plan — including the one `-l` created — is deleted, and if a delete fails JMeter stops with an error naming the file and whether it was readable and writable. In report-only mode (`-g`), only the first of those applies: the file passed to `-g` is the input and is never touched. The obvious caution is that `-f` is a recursive delete of a path you supplied on a command line, so a mistyped `-o` deletes whatever is at the mistyped path. ## Choosing between -f and a fresh path Both work, and they say different things: - **`-f`** keeps one stable location, which is convenient for a local loop or a workspace that is wiped anyway. It destroys the previous run's output every time. - **A dated folder** such as `reports/2026-09-08/` never collides, keeps history, and needs no destructive flag — at the cost of a path that something has to generate. A reasonable default is a dated results file and a dated report folder for scheduled runs, and `-f` for interactive work where you are re-running the same command repeatedly and do not care about the previous output.
- What does -f delete when it is used with -g instead of -e?Only the folder named by `-o`. In report-only mode there is no test and no result collector, and the file passed to `-g` is the generator's input, so it is never deleted. The results-file half of `-f` applies only to a run that is about to produce results.
- Why does the same command fail on its second run even after you delete the report folder?Because `-e` also requires the file named by `-l` to be absent or empty, and the first run filled it. The message is `Results file:<path> is not empty`. Delete it, use a fresh name, or pass `-f`, which clears the folder and the results files together.
saying these in an interview costs you the question
- Says JMeter overwrites the old report folder
- Thinks the check happens after the test finishes
- Uses -f without noticing it is a recursive delete
- Confuses the folder message with the results-file one
- Believes an empty folder is also rejected