---
title: "getUrlFilename"
description: "Extract the filename from a URL pathname, optionally including the extension, so downloads and asset labels are simple to derive."
canonical_url: "https://core.mhaibaraai.cn/en/docs/utilities/url/get-url-filename"
---
# getUrlFilename

> Extract the filename from a URL pathname, optionally including the extension, so downloads and asset labels are simple to derive.

## Usage

`getUrlFilename` extracts the filename from a URL.

```ts
import { getUrlFilename } from '@movk/core'

getUrlFilename('https://example.com/path/file.pdf') // 'file.pdf'
getUrlFilename('https://example.com/path/file.pdf', false) // 'file'
getUrlFilename('https://example.com/path/') // ''
```

## API

### `getUrlFilename(url, includeExtension?)`

Get the filename from a URL.

### Parameters

**url** (`string`) *required*: The URL string.

**includeExtension** (`boolean`): Whether to include the file extension. Defaults to true.

### Returns

**returns** (`string`): The filename.

## Changelog

See commit history for [src/utilities/url/parse.ts](https://github.com/mhaibaraai/movk-core/commits/main/src/utilities/url/parse.ts).

---

- [GitHub](https://github.com/mhaibaraai/movk-core/blob/main/src/utilities/url/parse.ts)


## Sitemap

See the full [sitemap](https://core.mhaibaraai.cn/sitemap.md) for all pages.
