> For the complete documentation index, see [llms.txt](https://bkortbus.gitbook.io/unreal-python-recipe-book/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bkortbus.gitbook.io/unreal-python-recipe-book/assets/asset-path-file-path.md).

# Asset Path ↔ File Path

In order to get the Asset Path for a File, or a File for an Asset Path, we'll need to use the [PackageTools ](https://dev.epicgames.com/documentation/en-us/unreal-engine/python-api/class/PackageTools?application_version=5.3#unreal.PackageTools)module. There are some quirks to be aware of, but it's pretty reliable.

## Systems File Path -> Unreal Asset Path

Getting the Unreal Asset path is fairly straight forward, if the resulting asset path is valid it means the asset does exist in the current Unreal Project:

```python
# The windows file path - your path goes here
file_path = "D:/projects/MyUnrealProject/Content/asset/path/demo.uasset"

# If the file path does exist in this Project, get its asset path:
asset_path = unreal.PackageTools.filename_to_package_name(file_path)
 
# Check if the asset path was found & exists
if asset_path and EditorAssetSubsystem.does_asset_exist(asset_path):
    print(f"found valid asset: {asset_path}")
```

## Unreal Asset Path -> Systems File Path&#x20;

Getting the File Path is a bit more involved, using the function as-is isn't always enough:

```python
from pathlib import Path
EditorAssetSubsystem = unreal.get_editor_subsystem(unreal.EditorAssetSubsystem)

asset_path = "/Game/some/asset/path"

# This uses pathlib.Path().resolve() to clean the file path,
# otherwise 
file_path = Path(unreal.PackageTools.package_name_to_filename(asset_path)).resolve()
print(f"found valid file path: {file_path} ({file_path.exists()})")

```

{% hint style="danger" %} <mark style="color:yellow;">Note</mark>: The resulting File Path from `package_name_to_filename()` might not include the extension, we'll have to take an additional step to find the valid file
{% endhint %}

<figure><img src="/files/2GeeuUXnU3rDWrcdbhQB" alt=""><figcaption></figcaption></figure>

If the extension is missing from the result, one option we can use is to scan the folder for any matches:

```python
from pathlib import Path
EditorAssetSubsystem = unreal.get_editor_subsystem(unreal.EditorAssetSubsystem)

def get_file_path_for_asset_path(asset_path) -> Path:
    file_path = Path(
        unreal.PackageTools.package_name_to_filename(asset_path)
    ).resolve()
    if file_path.exists():
        return file_path
    
    for test_path in file_path.parent.glob(f"{file_path.name}.*"):
        return test_path 
    
    unreal.log_warning(f"Could not find a valid system path for {asset_path}")
    return None

```

This function will:

1. Get the file path from the PackageTools function
2. If valid, return the result
3. otherwise, find and return the first file in the folder with our exact file name
