# How the Blober file_dir Path Template Variable Really Works

> Learn where Blober's file_dir value comes from, when it is empty, and how it preserves nested folders in custom destination paths.

## The Short Definition

`{file_dir}` is the directory path **relative to the folder you selected as the source boundary**. It is the part of the path that sits below that folder, not the file's full path and not always its immediate parent folder.

Blober works it out as it scans the files inside a folder you selected:

```text
file_dir = directory containing the file - selected folder path
```

This distinction determines whether a custom path template preserves nested source structure.

## Where You Use It

In a workflow:

1. Open **Source Configuration**.
2. Click **Browse Files and Folders**.
3. Select a folder and submit the selection.
4. Complete **Destination Configuration**.
5. Expand **Advanced Path Template (Optional)**.
6. Add `{file_dir}` to the **Template Pattern**.

A common preservation template is:

```text
{file_dir}/{filename}
```

This produces a clean filename when `{file_dir}` is empty and adds nested directories when it is not. Blober removes the empty path segment rather than creating a leading slash.

## Case 1: You Select an Individual File

Selected item:

```text
Clients/Acme/Final/report.pdf
```

Because you picked the file itself, Blober has no selected folder to measure it against. Its relative directory is `null`, which becomes an empty `{file_dir}` value.

```text
Template: {file_dir}/{filename}
Result: report.pdf
```

Blober does **not** produce:

```text
Clients/Acme/Final/report.pdf
```

The original parent path is not automatically inferred into `{file_dir}` for a directly selected file.

This matters when several individual files are selected from different folders. A `{file_dir}/{filename}` template will not recreate each file's original parent folder. If retaining those parent folders matters, select their containing folders instead.

## Case 2: You Select a Folder and the File Is at Its Root

Selected folder:

```text
Shoots/Wedding-2026
```

File:

```text
Shoots/Wedding-2026/cover.jpg
```

The file's containing directory and the selected folder are the same. The relative path between them is empty.

```text
{file_dir} = ""
Template: {file_dir}/{filename}
Result: cover.jpg
```

The selected folder name `Wedding-2026` is not included in `{file_dir}`. The selected folder is the boundary, so relative calculation starts **inside** it.

If you want the selected folder name in the destination, add it as static text:

```text
Wedding-2026/{file_dir}/{filename}
```

or select the parent folder `Shoots`, which changes the relative boundary.

## Case 3: You Select a Folder and the File Is Nested

Selected folder:

```text
Shoots
```

Nested file:

```text
Shoots/Wedding-2026/Camera-A/RAW/DSC_4821.ARW
```

Now the directory between the selected folder and the file is:

```text
Wedding-2026/Camera-A/RAW
```

Therefore:

```text
{file_dir} = Wedding-2026/Camera-A/RAW
```

and:

```text
Template: originals/{file_dir}/{filename}
Result: originals/Wedding-2026/Camera-A/RAW/DSC_4821.ARW
```

`{file_dir}` can contain several levels. It holds the full relative path between the selected folder and the file, not only the single parent folder directly above it.

## Selection Changes the Result

The same physical file can receive different `{file_dir}` values depending on the source selection.

File:

```text
Archive/2026/Client-A/Final/video.mp4
```

| Selected source               | `{file_dir}`          |
| ----------------------------- | --------------------- |
| The file itself               | empty                 |
| `Archive/2026/Client-A/Final` | empty                 |
| `Archive/2026/Client-A`       | `Final`               |
| `Archive/2026`                | `Client-A/Final`      |
| `Archive`                     | `2026/Client-A/Final` |

This is intentional. Selection defines the root that should not be repeated at the destination.

## Why file\_dir Matters With Custom Templates

Without a custom template, Blober can automatically preserve subdirectories when **Include Subdirectories** is enabled.

Once a custom template is entered, that automatic path is replaced. Consider:

```text
by-date/{file_created_date}/{filename}
```

Every qualifying file is grouped by date. Existing source subfolders disappear from the destination path.

To organize by date while retaining relative folders:

```text
by-date/{file_created_date}/{file_dir}/{filename}
```

For:

```text
Selected folder: Projects
File: Projects/Acme/Final/report.pdf
```

the result becomes:

```text
by-date/2026-07-18/Acme/Final/report.pdf
```

## Mixed File and Folder Selections

Blober allows multiple source selections. You can select one folder and several individual files.

Their `{file_dir}` values do not behave identically:

* Files discovered inside the folder receive a relative path beneath that folder.
* Files directly selected receive an empty value.
* Files at the selected folder's root also receive an empty value.

If the destination must retain a meaningful folder for every file, avoid mixing individual-file selection with a template that depends entirely on `{file_dir}`. Select common parent folders or add another stable prefix such as `{file_ext}` or `{file_created_date}`.

## Useful Templates

Preserve the relative hierarchy:

```text
{file_dir}/{filename}
```

Add an archive prefix:

```text
archive/{file_dir}/{filename}
```

Split by type while preserving hierarchy:

```text
{file_ext}/{file_dir}/{filename}
```

Group by creation date while preserving hierarchy:

```text
{file_created_date}/{file_dir}/{filename}
```

Rename while preserving hierarchy:

```text
{file_dir}/{file_created_datetime}_{filename}
```

## Common Mistakes

**Expecting the selected folder's name to appear.** It will not. `{file_dir}` starts below the selected folder.

**Selecting individual files and expecting parent folders.** Directly selected files have no relative selected-folder context, so `{file_dir}` is empty.

**Assuming Include Subdirectories adds folders to a custom template.** A custom path expression takes precedence. Add `{file_dir}` explicitly.

**Using `{file_dir}` without `{filename}`.** The variable describes directories, not the final filename. A template normally needs both.

## Verify It in Preview

Use a small test tree containing:

```text
Test/
  root.txt
  Level-1/
    nested.txt
    Level-2/
      deep.txt
```

Select `Test` and preview `{file_dir}/{filename}`. Expected relative results:

```text
root.txt
Level-1/nested.txt
Level-1/Level-2/deep.txt
```

That one preview demonstrates the complete rule before it is applied to a large archive.

Continue with the [complete Blober path-template guide](/kb/articles/blober-path-templates-complete-guide/) or learn how [selection and glob filters define which files reach the template](/kb/articles/blober-file-selection-glob-filters/).