{"record":{"id":"b33218f232870710","repo":"freqtrade/freqtrade","slug":"directory-directory-does-not-exist-b33218","errorCode":null,"errorMessage":"Directory '{directory}' does not exist.","messagePattern":"Directory '(.+?)' does not exist\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"freqtrade/data/btanalysis/bt_fileutils.py","lineNumber":72,"sourceCode":"    \"funding_fees\",\n]\n\n\ndef get_latest_optimize_filename(directory: Path | str, variant: str) -> str:\n    \"\"\"\n    Get latest backtest export based on '.last_result.json'.\n    :param directory: Directory to search for last result\n    :param variant: 'backtest' or 'hyperopt' - the method to return\n    :return: string containing the filename of the latest backtest result\n    :raises: ValueError in the following cases:\n        * Directory does not exist\n        * `directory/.last_result.json` does not exist\n        * `directory/.last_result.json` has the wrong content\n    \"\"\"\n    if isinstance(directory, str):\n        directory = Path(directory)\n    if not directory.is_dir():\n        raise ValueError(f\"Directory '{directory}' does not exist.\")\n    filename = directory / LAST_BT_RESULT_FN\n\n    if not filename.is_file():\n        raise ValueError(\n            f\"Directory '{directory}' does not seem to contain backtest statistics yet.\"\n        )\n\n    with filename.open() as file:\n        data = json_load(file)\n\n    if f\"latest_{variant}\" not in data:\n        raise ValueError(f\"Invalid '{LAST_BT_RESULT_FN}' format.\")\n\n    return data[f\"latest_{variant}\"]\n\n\ndef get_latest_backtest_filename(directory: Path | str) -> str:\n    \"\"\"","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/freqtrade/freqtrade/blob/1c8edfe4d1e8d11bd4b40e8fc3237c26c3a60e15/freqtrade/data/btanalysis/bt_fileutils.py#L54-L90","documentation":"ValueError raised by `get_latest_result_file`-style helpers in bt_fileutils when the backtest-results directory passed in (e.g. `user_data/backtest_results`) does not exist. It is the first of three validation steps: directory exists → `.last_result.json` exists → contains the expected key.","triggerScenarios":"Calling `freqtrade backtesting-show` / `freqtrade webserver` analysis or the Python helpers with `--export-filename`/directory pointing to a non-existent path; `directory.is_dir()` is False.","commonSituations":"No backtest has ever been run (directory not created yet), custom `exportfilename` path typo, docker volume not mounted at the expected location.","solutions":["Run a backtest with `--export trades` first so results and the directory exist","Verify the directory: `ls user_data/backtest_results`","Fix the path/typo passed via `--export-filename` or the helper's `directory` argument"],"exampleFix":"# before\nfreqtrade backtesting-show --export-filename /tmp/nope\n\n# after\nfreqtrade backtesting --export trades\nfreqtrade backtesting-show --export-filename user_data/backtest_results/","handlingStrategy":"validation","validationCode":"from pathlib import Path\nd = Path('user_data/backtest_results')\nif not d.is_dir():\n    raise SystemExit(f'{d} missing — run a backtest with --export first')","typeGuard":null,"tryCatchPattern":"try:\n    fn = get_latest_backtest_filename(directory)\nexcept ValueError as e:\n    print(e)\n    sys.exit(1)","preventionTips":["Standardize on user_data/backtest_results for exports","Verify the directory exists before calling backtesting-show or btanalysis helpers"],"tags":["backtest","filesystem","results"],"backgroundTag":null,"analyzedSha":"1c8edfe4d1e8d11bd4b40e8fc3237c26c3a60e15","analyzedAt":"2026-08-15T05:09:08.096Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}